After opening a file in append update mode, is it necessary to execute a file positioning statement before each write to the file?
FILE *h; int ch; if ((h = fopen("data", "a+")) == NULL) exit(1); if (fseek(h, 0 SEEK_SET)) exit(2); ch = fgetc(h); /* read very first character */ if (ch == EOF) exit(3); /* redundant? mandatory? */ fseek(h, 0, SEEK_END); /* call file positioning before output */ /* add 1st character to the end of file on a single line*/ fprintf(h, "%c\n", ch);
The C11 Standard says:
220.127.116.11/6 ... all subsequent writes to the file to be forced to the then current end-of-file ...
18.104.22.168/7 ... input shall not be directly followed by output without an intervening call to a file positioning function ...
I take it the shall in 22.214.171.124/7 is stronger than the description in 126.96.36.199/6.