scanf : scanf « stdio.h « C Tutorial






ItemValue
Header filestdio.h
Declarationint scanf(const char *format, ...);
Functionread input.


The control string pointed to by format consists of three classifications of characters:

  1. Format specifiers
  2. White-space characters
  3. Non-white-space characters

The scanf() Format Specifiers

CodeMeaning
%aRead a floating-point value (C99 only)
%ASame as %a (C99 only)
%cRead a single character
%dRead a decimal integer
%iRead an integer in either decimal, octal, or hexadecimal format
%eRead a floating-point number
%ESame as %e
%fRead a floating-point number
%FSame as %f (C99 only)
%gRead a floating-point number
%GSame as %g
%oRead an octal number
%sRead a string
%xRead a hexadecimal number
%XSame as %x
%pRead a pointer
%nReceive an integer value equal to the number of characters read so far
%uRead an unsigned decimal integer
%[ ]Scan for a set of characters
%%Read a percent sign


#include <stdio.h>

  int main(void)
  {
    char str[80], str2[80];
    int i;

    /* read a string and an integer */
    scanf("%s%d", str, &i);

    return 0;
  }








22.31.scanf
22.31.1.scanf