Use of scanf functions in C Language

Source: Internet
Author: User

Author: Teacher Zhuang,Hua Qing vision embedded college lecturer.

Scanf () function control string

Function Name: scanf

Function: format the input.

Usage: int scanf (char * Format [, argument,...]);

The scanf () function is a common terminal formatting input function that reads input information from the standard input device (keyboard. You can read any inherent type of data and automatically convert the value into an appropriate internal format.

The call format is scanf ("<formatted string>", <Address Table> );

The scanf () function returns the number of successfully assigned data items. If an error occurs, EOF is returned.

Its Control string consists of three types of characters:
1. format the specifier;
2. Blank characters;
3. Non-blank characters;

(A) Format the specifier

Format Character Description
% A reads a floating point value (valid only for c99)
% A same as above
% C reads one character
% D read a decimal integer
% I reads decimal, octal, and hexadecimal Integers
% O read an octal integer
% X reads hexadecimal Integers
% X same as above
% C reads one character
% S reads a string
% F reads a floating point number
% F same as above
% E Same as above
% E Same as above
% G same as above
% G same as above
% P reads a pointer
% U reads an unsigned decimal integer
% N number of equivalent characters that have been read to this point
% [] Scan Character Set combination
% Read % symbol

Additional format description
Modifier description
L/L length modifier input "long" Data
H-length modifier input "short" Data
W integer constant specifies the width of input data
* An asterisk is used to read data.
HH, ll, same as H, l, but only valid for c99.

(B) white space characters

The blank character will slightly remove one or more blank characters in the reading operation of the scanf () function. The blank character can be space, tab, newline, and so on until the first non-blank character appears.

(C) Non-blank characters

A non-blank character will cause the scanf () function to remove the same character as this non-blank character during reading.

Source:Huaqing vision embedded College,Original article address:Http://www.embedu.org/Column/Column681.htm

For more articles, see the instructor's blog>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.