Pointer to the file stream from which input is to be read
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
A null-terminated string specifying the input format, including conversion specifiers
3rd Parameter Type : ...
Represents a variable number of arguments in a function. Used in functions like `printf` or `fprintf` to accept additional parameters beyond those explicitly declared.
3rd Parameter
Variable number of pointers where the converted input values will be stored
Read more about parameters of fscanf in parameters section
The fscanffunction in C language Reads formatted input from a stream.
The fscanf function reads input from the stream pointed to by stream, under control of the string pointed to by format that specifies the admissible input sequences and how they are to be converted for assignment, using subsequent arguments as pointers to the objects to receive the converted input. This function is similar to scanf, but reads from a specified stream instead of stdin.
The fscanffunction takes 3
parameters:
•
FILE * `stream`: Pointer to the file stream from which input is to be read
•
const char * `format`: A null-terminated string specifying the input format, including conversion specifiers
•
... `args`: Variable number of pointers where the converted input values will be stored
Reads formatted input from the specified file stream according to the format string and stores the results in the locations pointed to by the provided arguments. Returns the number of input items successfully matched and assigned, or `EOF` if an error occurs or the end-of-file is reached before any conversion.
The fscanf function return value :
Returns the number of input items successfully matched and assigned
This can be fewer than provided for, or even zero, in the event of an early matching failure
EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs
Output
This example demonstrates the basic usage of `fscanf`. It reads an integer, a string, and a float from a file named 'data.txt'. The file should contain these values separated by spaces.