tech on the net
Home About Us Feedback Site Map

Microsoft

Access Excel Word

Database

SQL Oracle / PLSQL SQL Server MySQL MariaDB PostgreSQL

Web Development

HTML CSS Color Picker

Language

C Language

More

ASCII Table Linux UNIX Java Clipart Joke of the Moment

Other Sites

CheckYourMath BigActivities DigMinecraft
Share this page:

C Language: scanf function
(Formatted Read)

In the C Programming Language, the scanf function reads a formatted string from the stdin stream.

Syntax

The syntax for the C Language scanf function is:

int scanf(const char *format, ...);

Parameters or Arguments

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 10.500000
%.1f Reads a floating-point number 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 number in either fixed decimal or exponential format depending on the size of the number 10.5

Returns

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

#include <stdio.h>

Applies To

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

Similar Functions

Other C functions that are similar to the scanf function:

See Also

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