fscanf() in C with Examples

The fscanf() is a C Library function which reads formatted input from the stream. fscanf reads data from the file which is pointed by File Pointer. If you want to read data from the file which saved in a readable format then you can use this function.

Basic Syntax

Following is the basic syntax for fscanf() C library function wich is available by default.

int fscanf(FILE *stream, const char *format, …)

And the parameters are as given below:

ParameterDescription
streamPointer to file object for identification of string.
formatFormat specifier present in [=%[*][width][modifiers]type=] format.
where,

  • * = (Optional) Asterisks that shows that data is to be read from stream
  • width = The Maximum number of characters to be read
  • modifiers = Indicates size difference for data pointed by the corresponding argument.
  • type = Type of data is a character which indicates the type of data

Return Value

The fscanf() function returns all the input items matched and assigned with the given format.

Example

Below is an example for fscanf() C Library function.

The output should be:

NAME
Ashwini
Rutuja
Priyanka
Abhijeet

LEAVE A REPLY

Please enter your comment!
Please enter your name here