Scanf() function Format Specifiers - C Language Basics

C examples for Language Basics:scanf

Introduction

The input format specifiers are preceded by a % sign.

It tells scanf( ) what type of data is to be read next.

These codes are listed in the following table.

Code Meaning
%a Reads a floating -point value (C99 only).
%c Reads a single character.
%d Reads a decimal integer.
%i Reads an integer in either decimal, octal, or hexadecimal format.
%e Reads a floating -point number.
%f Reads a floating -point number.
%g Reads a floating -point number.
%o Reads an octal number.
%s Reads a string.
%x Reads a hexadecimal number.
%p Reads a pointer.
%n Receives an integer value equal to the number of characters read so far.
%u Reads an unsigned decimal integer.
%[ ] Scans for a set of characters.
%% Reads a percent sign.

The format specifiers are matched, in order from left to right, with the arguments in the argument list.


Related Tutorials