given a file (file.txt
) with the following content:
123 456
789 101
I don't understand why after that I read from the file the first line (by fscanf
) it's not work to read the second line.
int main() {
FILE* fp = fopen("file.txt", "r");
if (fp == NULL)
return 1;
int n1, n2;
fscanf(fp, "%d %d", &n1, &n2);
char buffer[10]="";
fgets(buffer, 10, fp);
printf("%s", buffer);
}
What is the problem? (I tried to add \n
in the format of fscanf and then it's works, but I don't understand why I must add \n
to the format of fscanf
?)