C Escape Character and format controller reference

Source: Internet
Author: User
Tags integer numbers
Escape Character reference:

/A: beep and bell
/B: Roll Back: one row backward
/F: Form feed
/N: line feed, cursor to the beginning of the downstream line
/R: Press enter and move the cursor to the beginning of the line.
/T: horizontal tabulation
/V: vertical tabulation
//: Backslash
/': Single quotes
/": Double quotation marks
/? : Question mark
/DDD: three octal nodes
/Xhh: two-digit hexadecimal format
/0: NULL. Nothing is done.

Note:
1,/V vertical tabulation and/F break do not affect the screen, but will affect the printer to perform the response operation.
2,/N should actually call the carriage return to wrap the line. Line feed only changes one line without changing the horizontal coordinates of the cursor. Press enter to return to the beginning of the line without changing the vertical coordinates of the cursor.
3,/t move the cursor forward four or eight cells, which can be set in the Compiler
4,/'is used in characters (that is, in single quotes. It is not required in the string (that is, double quotation marks). You only need to use.
5 ,/? Actually not necessary. As long as it is used? You can (verify in Windows vc6 and TC2 ).

For details about the format controller, refer:

Format output character: printf

Use: Output several types of arbitrary data to the terminal.

Format: printf (format controller, output List)

Note:

Format Controller: % format specifier.

-Specify the left-aligned output.

0: Fill in the specified blank space.

M. N specifies the output domain width and accuracy.

Correction of the output length of L. H.

The format character specifies the output data type.

Note:

Format character: Specifies the data type and output format of the output item.

D: A signed decimal integer.

O unsigned octal number.

X unsigned hexadecimal number. (In lowercase x format, lowercase letters a, B, c, d, e, f are used to represent the numbers between 10 and 15, uppercase X uses uppercase abcdef to represent the number between 10 and 15)

An unsigned decimal integer of u.


Basic INTEGER: two bytes, sixteen bits (BITs)

11 11 11 11 11 11 11 11 11 equals 65535.

11 11 11 11 11 11 11 10 equals-2.

The first (symbol bit) of a negative number is 1. How can I get the complement of a negative number: the original code is reversed by adding one. The binary number of 2 is: 00 00 00 00 00 10. The inverse value is equivalent to 11 11 11 11 11 11 11 01, and then 1. the binary number goes into two places, so we can get the binary code of-2.

 

You can use % d to output signed integer numbers.

Unsigned integer numbers can be output using % u.

The number stored in the computer is a binary number. The highest bit is a symbol bit or a data bit, which can be controlled by an output format character.

 

Binary Number to octal number: Three 1 corresponds to one 7.

Binary Number hexadecimal number: Four Binary numbers correspond to one hexadecimal number, and four 1 corresponds to one F.

 

Note:

Format character: c Outputs one character.

S outputs a string.

E. output the real number in exponential form.

F outputs the real number in decimal form.

G automatically determines that the output format is short in E and F, and does not print invalid zeros.

% Output %.

 

Note: For Single-precision data output using the % F format, only the first seven digits are valid digits and the decimal digits are 6 digits.

For the double-precision number, when the % lf format operator is used for output, the first 16 digits are valid digits with 6 decimal digits.

 

Length Modifier

L: specify a long integer for an integer.

Example: % lD, % lx, % Lo, % lu

Specify double precision for the real type

Example: % lf

H: only used for integer format character correction to short

Example: % HD, % HX, % ho, % Hu

For 64-bit integer input and output, in the C ++ environment on poj (that is, VC ++), the 64-bit integer is:
_ Int64
The input/output format is "% i64d ".

In G ++, the 64-bit integer is
Long long
The input and output formats are "% LLD ".

Description of domain width and Accuracy

M: The domain width, that is, the number of characters that the corresponding output items occupy on the output device.

If the actual data width is greater than m, the output is based on the actual data width.

Actual data width <m, left blank.

N: precision, indicating the number of decimal places of the output real number.

 

Notes:

The Compiling Program only checks the call form of the printf function and does not analyze the format control string. If the format character does not match the type of the output item, no type conversion is performed. (The number of outputs is random)

The format characters must contain lowercase letters.

The format control string can contain escape characters.

Normal characters in the format control string are output as is.

Parameters of an output item can be expressions and function calls in addition to constants and variables.

% G, % F, and % E are used to print floating point values.
The % G format is especially useful for printing floating-point numbers that do not require column-aligned. It has two functions:
1. Remove the excess zero at the end of the number (the number does not reach six digits)
2. Retain the six valid digits (the remaining six digits)
When the % eformat is used to print floating point numbers, it is displayed in the exponential form. For example, when the circumference rate is output, it is 3.141593e + 00.
Differences between the two:
The number printed in % G format is a total of 6 Valid digits.
% Eformat: print the 6-digit valid number after the decimal point
% F do not use an exponential representation of floating point numbers. Therefore, the circumference rate is 3.141593.
(But pay attention to its precision requirement: it is also a 6-digit valid number after the decimal point)
(8) % is used to print a % character.
(9) % E and % G only replace lowercase letters (e) with uppercase letters (e) in the output)

Tips for outputting positive and negative numbers, for example:
Printf ("% + D/N",-5, 0, 5 );
You only need to add a "+" in the middle. The role is to output the sign bit (that is, the plus or minus sign of the number)
If you do not want the '+' sign to appear before a positive number, use the following method:
You only need to add a space in the middle. For example:
Function: If a number is non-negative, a space is inserted before it.
Int I;
For (I =-3; I <= 3; I ++)
Printf ("% d/N", I); // note that there is a space between % and D.

Tips for sscanf:
To break down strings, many functions require the knowledge of regular expressions, so we will introduce several simple methods to use sscanf to break down strings.
1.
Char STR [2, 100], str1 [100], str2 [100];
Gets (STR );
Sscanf (STR, "% S % s", str1, str2 );
Splits the entire line of string into two strings by space, tab, or carriage return.
2
Returns the string of the specified length. In the following example, a string with a maximum length of 4 bytes is obtained.
Sscanf ("123456", "% 4 s", STR );

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.