fscanf function(Formatted File Read) in C Language – example and detail

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

Syntax

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

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

Parameters or Arguments

stream The circulate the place the output will be read. format Describes the enter as well as gives 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 wide variety in fixed decimal structure 10.500000 %.1f Reads a floating-point wide variety with 1 digit after the decimal 10.5 %e Reads a floating-point number in exponential (scientific notation) 1.050000e+01 %g Reads a floating-point range in either constant decimal or exponential layout relying on the dimension of the variety 10.5

Returns

The fscanf feature returns the number of characters that was read and stored. If an error happens or end-of-file is reached before any gadgets should be read, it will return EOF.

Required Header

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

#include <stdio.h>

Applies To

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

ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the fscanf function:

scanf function sscanf feature

See Also

Other C features that are noteworthy when dealing with the fscanf function:

fprintf function printf characteristic sprintf characteristic vfprintf function vprintf function vsprintf characteristic