Instead of appending “abc” (and thus eventually getting a file full of abcabcabc….), no matter how many times I run this, myfile only containst “abc”…. how can I append?
#include <stdio.h>
#include <string.h>
int main(){
char strng[10];
strcpy(strng,"abc");
FILE *my_file;
my_file = fopen("myfile","a+");
if (my_file == NULL){ printf("problem\n");}
fwrite(strng, sizeof(strng), 1, my_file);
printf("appending %s\n",strng);
fclose(my_file);
}
Apart from the fact that:
should be:
it works for me.