0

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;
}
AlexQualcosa
  • 467
  • 6
  • 11

0 Answers0