I'm trying to write data into a file using C. I wrote the below code.
#include<stdio.h>
void main(){
FILE *f1;
char c;
printf("Data Input\n\n");
f1 = fopen("INPUT", "w");
while((c = getchar()) != EOF) putc(c, f1);
fclose(f1);
printf("\nData Output\n\n");
f1 = fopen("INPUT", "r");
while((c=getc(f1)) != EOF) printf("%c", c);
fclose(f1);
}
But the code is behaving abnormally. The below pic is the output.
I had to enter EOF three times to make it work. I don't understand why this is happening. Is there any error in my code? I'm using Dev-C++ 5.6.3
Thanks in advance.