I am a newcomer to programming. My English is bad so I used google translate to ask this question:
I'm practicing using input/output in C language. I wrote a C program that takes a file called sample.txt and writes a few lines of words in it. I feel that the program that I made is correct but I found an error when compiling the program.
#include <stdio.h>
int main(){
FILE *fptr;
int n,I;
char text[100];
fptr=fopen("sample.txt","w");
printf("Number of line? ");
scanf("%d",&n);
printf("\n");
for( i = 1; i <= n; i++){
printf("Line %d: ", I);
fgets(text, sizeof(text), stdin);
fputs(text, fptr);
}
fclose(fptr);
return 0;
}
This is the output : enter image description here. enter image description here
Why line 1 and 2 are not separate like the others? I've checked several times and I don't know what went wrong.