scanf()that will work on any file, not just the standard input and standard output ones. They are called
fscanf()and we use them only on text files.
Suppose we wanted to put a line of text into a file that
contained the name, ID number and GPA of student number
where each student is in a structure.
We could use a statement like:
fprintf(fp, "%s %d %f\n", students[i].name, students[i].id, students[i].gpa);
fscanf(fp, "%d%d", &x, &y);
The basic use of
is just as it is for
We just have to remember to put the file pointer variable as the
As a side note, in some implementations,
a shorthand for
They really use the same code.