file io - appending in C failing, simply overwriting -
Instead of adding "ABC" (and thus finally a file is filled with abcabcabc ....), no matter how many The times I run it, only include myfile "abc" .... How can I add?
#include & lt; Stdio.h & gt; #include & lt; String.h & gt; Int main () {char strng [10]; Strcpy (strng, "abc"); File * my_file; My_file = fopen ("myfile", "a +"); If (my_file == NULL) {printf ("problem \ n");} filitt (strng, sizeof (strng), 1, my_file); Printf ("add% s \ n", strng); Fclose (my_file); }
except for this fact:
(Strang, strang, 1, my_file);
should be:
filitt (strng, strlen (strng), 1, my_file);
This works for me.
Comments
Post a Comment