Could someone tell me why the file doesn't change? It works when I use rewind
or fseek
but not otherwise.
What's the standard way of using fputs
after fgets
. The file indicator is at position 9 so fputs
must write after that, but it doesn't do anything.
In file:
abcd efgh ijkl mnor
In source code:
char c;
char str[15];
FILE *fp = fopen("d:\data.txt","r+");
fgets(str, 10, fp);
// fseek(fp, 9, SEEK_SET);
// rewind(fp);
printf("%d
", ftell(fp));
// ftel shows that it's in "9".
printf("%s", str);
fputs(str, fp);
// why its not working
fclose(fp);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…