This is more of a general coding question I'm curious about. This is a program that determines how many years it would take for a savings account to deplete if you withdraw a certain amount each...
Type: Posts; User: atac
This is more of a general coding question I'm curious about. This is a program that determines how many years it would take for a savings account to deplete if you withdraw a certain amount each...
I don't think he's gonna have that problem for whats he's doing.
You should look up documentation on fgets and sscanf, but you could do something like this.
int getInt(){
const int STR_SIZE = 20;
int integer;
char stringInt[STR_SIZE];
...
Look at your inner for loop:
it doesn't execute on the first row
it executes once on the second row *
it executes twice on the third row **
it executes three times on the fourth row ***
Thats...
You shouldn't have to change it too much. The first one, for example:
fgets(label[i].name, FNAME, stdin);
Also refer to fgets - C++ Reference
Keep in mind, fgets() appends a newline at...
I sorted of skimmed through your code but it sounds like to need to clear the input buffer after entering an the integer. When you enter an int and hit enter the newline character is skipping the...
Thanks, I accidentally included the code for a user to input the string, but removed it because I wanted to get feedback on the logic of the function instead of the technicals of C.
Just out of the blue I decided to write a trim function, it took me a little while but eventually got it. Can anyone offer some tips on how to optimize it if possible. I feel like theres gotta be...
It appears that when you enter command line arguments or use fgets() to input a string you can assign that string to another string variable using the assignment operator. But when you read from a...
Alright, in case anyone else is trying to figure this out I think I got it. You need to work with money in cents. So $35.96 is 3596 in pennies, you need to store that number in an int. If you are...
I know you don't want to use floating point numbers when working with money because of the rounding errors, but instead use integers. I read somewhere that you should "multiply by 100, add 0.5,...
*Smacks forehead*
Thank you both, good suggestion ooga!
In the shuffleDeck function, I'm printing out "cards" in the while loop and I'm getting junk after some of the strings along with a segfault at the bottom of the list. I tried using realloc, in order...
That code I posted was just a quick example, in my actual program I checked for a NULL file and used free() for the dynamic memory alloc. But I wasn't aware casting malloc was bad practice, thanks.
Nevermind, I just figured it out! I wasn't terminating the strings in the array itself.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]){
I'm making a Jeopardy game and when I read text from a file into arrays to set the categories, questions and answers a couple of the strings are not terminating and they are printing that junk box...
I'm reading text from a file into an array of strings, when I run the program like this everything works fine, but if I comment out the lines "char letter = 'A'" and the printf two lines below it,...
Does anyone know why when I print out "array[2]" nothing prints? It just prints blank space. My file definitely has text in it, but when I try to assign "text" into the array of pointers it won't...
Hmm, the problem with that ^^^ is that it excepts 0 as a valid answer. I would do:
while(number < 1 || number > 10){
puts("Incorrect Input");
scanf("%d", &number); ...
I'm writing an addition and subtraction calculator that takes input as: 5+6-3+2. You should be able to add or sub as many numbers as you want. I want the while loop to stop when the user hits enter....
I'm writing a program that outputs a random question from a file. In the file, I have each question numbered like this 1-5:
1 Question
multiple choices...
2 Question
multiple choices...
...
I never got those warnings. Everything complied fine for me, but I made those changes you mentioned anyway.
Everything works fine until I enter a binary number that has more than 10 digits. In that case, if I enter eleven '1's, sum will equal 1024 (which is the 10th power of 2) and its not adding the rest....
This was my systematic method of checking if the first string contains the second:
"aaabababaaasdfg" - (first) string
"absd" - (second) string
a (second) = a (first), so
move to next...
My friend gave me this question that he got on a job interview. You're trying to see if its possible for firstString to equal secondString by simply deleting characters in the firstString. You're not...