C Language Input/Output Format

Source: Internet
Author: User
C language does not provide input and output statements. Input and Output operations are completed by C library functions. But it must contain the header file stdio. h.
Putchar () Outputs a character to the terminal
Printf () format characters:
① D is used to output a decimal integer.
% D output according to the actual length of Integer Data
% MD sets the output length to M. If the data length is smaller than m, the left space is filled. If the data length is greater than m, the actual output length is
% LD output long integer data
② The o Format operator outputs integers in octal form
③ X format operator outputs integers in hexadecimal format
④ U format character is used to output unsigned data, which is output in decimal format
⑤ The C format character is used to output a character
6 s format character to output a string
% S output actual length string
% Ms output string occupies m column. If the string length is smaller than m, left spaces are filled. If the string length is greater than m, the actual output is
%-MS output string occupies m column. If the string length is smaller than m, right fill space,
% M. Ns output occupies the m column, but only the n characters on the left of the string are taken and aligned on the right.
%-M. Ns M, N indicates the same as above, and is aligned to the left. If n> M, M automatically obtains n.
7. The F format operator outputs real numbers in decimal form
% F integer part all output, decimal part output 6 digits
% M. NF output data occupies a total of M columns, with N decimal places. If the value length is less than m, fill in spaces at left.
%-M. NF same as above, right fill space
Returns the real number in an exponential form.
% E the system specifies 6 decimal places and the 5-digit index (E + 002)
Returns the real number in the ⑨ g format. The F format or the eformat is automatically selected based on the value size.

3. Data Input

Getchar () input a character from the terminal
Scanf (format control, address list) Standard C scanf does not use % u. For unsigned data, enter % d, % O, or % x. * After % is used to skip the corresponding data. When inputting data, it cannot be specified that the precision, such as scanf ("% 7.2f", & A); is illegal.

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.