C - File buffer rewind() writing blank file cannot read

97 Views Asked by At

This program uses the rewind () function, why in the following case, the rewind () function makes true the condition for which the buffer must be flushed?

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char * argv[])
{

       FILE * file_output = fopen("output.txt", "w+");
       char ch;

       printf("Insert a character: ");
       scanf("%c", &ch);
       while (getchar() != '\n');

       putc(ch, file_output);
       rewind(file_output); // <-- TEST THIS CODE WITH AND WITHOUT REWIND()

       printf("Read character: ");
       printf("%c\n", getc(file_output));

       fclose(file_output);

       return 0;
}
0

There are 0 best solutions below