totn C Functions

C Language: sscanf function
(Formatted String Read)

In the C Programming Language, the sscanf function reads formatted output from an object pointed to by s.

Syntax

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

int sscanf(const char *s, const char *format, ...);

Parameters or Arguments

stream
An array 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:

FormatExplanationExample
%dReads an integer10
%fReads a floating-point number in fixed decimal format10.500000
%.1fReads a floating-point number with 1 digit after the decimal10.5
%eReads a floating-point number in exponential (scientific notation)1.050000e+01
%gReads a floating-point number in either fixed decimal or exponential format depending on the size of the number10.5

Returns

The sscanf 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 sscanf function is:

#include <stdio.h>

Applies To

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

  • ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the sscanf function:

See Also

Other C functions that are noteworthy when dealing with the sscanf function: