fprintf is buggy
i am using straight c for a project and i am attempting to write a series of integers to a file usign fprintf. the file is already opened (and confirmed to be present) and puts() works fine with it. however, when i use fprintf(file, "%n\n" number) i get an access violation from within the bowels of fprintf. i don't understand it. the same result is acheived with sprintf() and printf(). Any guesses would be greatly appreciated. Thanks.
personwholives
What compiler you are using, what is the definition of 'number', and what are the lines of code concerned with the 'file' variable?
You missed a comma before 'number' in your post btw.
You missed a comma before 'number' in your post btw.
Quote:Original post by flureExactly. %n interprets its parameter as a pointer to an integer and sets the pointed-to value to the number of characters written so far:
just replace %n by %d
int six = 6, nine = 9;printf("%i * %i =%n", six, nine, &nine);printf(" %i", six*nine);
fprintf takes 3 arguements:
fprintf(filepointer, control string, variables.....);
in the control string you can have differnt formats that corespond to the variables after the control string.
%d = integer
%f = float
%lf = double
there are more, but im too lazy.
basically, the call you should have been making looks like this:
fprintf(file, "%d \n", number);
cheers
fprintf(filepointer, control string, variables.....);
in the control string you can have differnt formats that corespond to the variables after the control string.
%d = integer
%f = float
%lf = double
there are more, but im too lazy.
basically, the call you should have been making looks like this:
fprintf(file, "%d \n", number);
cheers
General hint: Whenever you suspect there is a bug in your compiler or the standard library, there is not, you are doing something wrong. Of course this is not the case 100% of cases, but it is in 99.999923% at the very least.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement