user2279298
user2279298

Reputation: 31

How to add data at the end of a file

I would like to open a file and add data at the end of the file which the user has input and stored in a variable amt.

But my code is not working..

{
 fp=fopen("TRECIEPT.TXT","a+");
 while((temp=getc(fp))!=EOF);
 fprintf(fp,"\n");
 fprintf(fp,"%llu",&amt);
}

Upvotes: 0

Views: 113

Answers (1)

NPE
NPE

Reputation: 500953

1) The following loop is unnecessary:

while((temp=getc(fp))!=EOF);

The "a+" already takes care of seeking to the end of the file.

2) The & in following is likely wrong:

fprintf(fp,"%llu",&amt);

3) Don't forget to close the file when you're done with it.

Upvotes: 4

Related Questions