I'm trying to understand file streams and how they work and I'm still a little frustrated as to why this code wouldn't work - without calling fseek,
Code:
/*manipulating files in place */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main(int argc, char *argv[]){
int ch,lower;
FILE *file;
if ( (file = fopen(argv[1], "r+") ) == NULL){
puts("Unable to open file");
getchar();
return 1;
}
while( ( ch = fgetc(file) ) != EOF){
if( (isupper(ch) ) )
tolower(ch);
}
if ( fclose(file) !=0)
puts("Unable to close file");
getchar();
return 0;
}
I got this
If the file is opened in the update mode (+), then output cannot be directly followed by input and input cannot be directly followed by output without an intervening fseek, fsetpos, rewind, or fflush.
but why?