Hello, I have a slight problem regarding fprintf.
Basically, I am asking the user to input a number:
printf("%d\n", get_id("Enter the Number (100000-999999): ", 99999, 1000000));
but when it comes to printing it to a text file, i'm not sure what to write for the variables part:
fp = fopen("C:\\test.txt", "w");
fprintf(fp, "%d", ???);
question marks indicate that I don't know what to put in there. I made the get_id() function in another file in which the function returns the value "n". n being the number the user inputs. I'm not sure if that helped.
Any help would be much appreciated. Thanks.
C programming file printing?
You put there the variable names you want written to the file, one for each %-specification in the second parameter.
I suspect you're also missing the saving of the value that get_id probably returns. What I think your code should look like is this:
int id;
id = get_id( ....whatever );
fp = fopen( ....);
fprintf( fp, "%d", id );
Good luck.
Reply:fprintf and printf work exactly the same except for the file pointer.
hollyhock
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment