C scanf function


The scanf function reads information from a standard input device (keyboard). scanf function has the following general format.


scanf("conversion specifier", variable);


The conversion specifier argument tells scanf how to convert the incoming data.

scanf starts with a string argument and may contain additional arguments. Additional arguments must be pointers. scanf returns the number of successful inputs.


Conversion Character Displays Argument (Variable's Contents) As
%c Single character
%d Signed decimal integer (int)
%e Signed floating-point value in E notation
%f Signed floating-point value (float)
%g Signed value in %e or %f format, whichever is shorter
%hd (signed) short int
%hu unsigned short int
%i Signed decimal integer (int)
%ld (signed) long int
%o Unsigned octal (base 8) integer (int)
%s String of text
%u Unsigned decimal integer (int)
%lu unsigned long int
%x Unsigned hexadecimal (base 16) integer (int)

Home »
  C Language »
    Input / Output »