scanf : scanf « stdio.h « C Tutorial

Home
C Tutorial
1.Language
2.Data Type
3.String
4.printf scanf
5.Operator
6.Statement
7.Array
8.Function
9.Structure
10.Pointer
11.Memory
12.Preprocessor
13.File
14.Data Structure
15.Search Sort
16.Wide Character String
17.assert.h
18.ctype.h
19.math.h
20.setjmp.h
21.signal.h
22.stdio.h
23.stdlib.h
24.string.h
25.time.h
26.wctype.h
C Tutorial » stdio.h » scanf 
22.31.1.scanf
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.