r+ in fopen doesnt let me read and write at the same time
Hello.
When I open a file using fopen, and i set the mode to r+ (that supposedly allows me to read and write in that file at the same time), and then when i try to read or write in it, only the first thing i try works, for example:
Code:
int main() {
FILE *file;
file = fopen("test.txt", "r+");
char a = fgetc(file);
fputc('a', file);
printf("%c", a);
fclose(file);
}
in this case, only fgetc() would be succesfully executed, while fputc would be ignored. If I put fputc() first and then fgetc(), then it would be fgetc() the ignored function?
What am I doing wrong here? why cant i read and write at the same time?