Click to See Complete Forum and Search --> : C: writing to a file


threadhead
02-23-2003, 01:56 PM
hi there.

i was coding a program that creates a file and uses the fprintf()
call to write to the file.
i am closing the filedescriptor with fclose() when the program exits.

so here is my problem:
lets assume i have been writing to a file successfully. now the program exits.

i execute the program a second time and want to write again to the same
textfile.
but i dont want the file to be replaced, but the text should be appended to the end of the file.

how can i do that?

thanks

bwkaz
02-23-2003, 02:15 PM
A check of the fopen man page would have found this:

FILE *fp = fopen("filename", "at"); ;)

a for append, t for text.

threadhead
02-23-2003, 02:25 PM
hey thanks! :D

i searched the fputs and fprintf manual pages instead of the fopen ones.

too bad. ;)