# fprintf is buggy

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
just replace %n by %d

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by flurejust replace %n by %d
Exactly. %n interprets its parameter as a pointer to an integer and sets the pointed-to value to the number of characters written so far:
int six = 6, nine = 9;printf("%i * %i =%n", six, nine, &nine);printf(" %i", six*nine);

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
fprintf is not buggy.

##### Share on other sites
sorry, i figured it out shortly after i made this post, but my stupid school dropped the internet connection for most of the night.

• 37
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631360
• Total Posts
2999556
×