C Language: fscanf function(Formatted File Read)

In the C Programming Language, the fscanf function reads formatted output from stream.

Syntax

The syntax for the fscanf function in the C Language is:




int fscanf(FILE *stream, const char *format, ...);



Parameters or Arguments

stream

The stream where the output will be read.

format

Describes the input as well as provides a placeholder to insert the formatted string. Here are a few examples:

Format Explanation Example
%d Reads an integer 10
%f Reads a floating-point number in fixed decimal format 20.500000
%.1f Reads a floating-point number with 1 digit after the decimal 20.5
%e Reads a floating-point number in exponential (scientific notation) 2.050000e+01
%g Reads a floating-point number in either fixed decimal or exponential format depending on the size of the number 20.5

Returns

The fscanf function returns the number of characters that was read and stored. If an error occurs or end-of-file is reached before any items could be read, it will return EOF.

Required Header

In the C Language, the required header for the fscanf function is:




#include 



Applies To

In the C Language, the fscanf function can be used in the following versions:

  • ANSI/ISO 9899-1990

stdio.h Functions





Instagram