Escape characters in C Language

Source: Internet
Author: User

When I changed the code today, I found an escape character '/012', Which is inexplicable. I searched the internet:

 

Escape characters are a special form of characters in C. Generally, escape characters are used to indicate non-printable control characters in the ASCII character set and special function characters. For example, a single marker (') is used to represent a character constant ('), it is used to represent the double apostrophes (") and backslash (/) of string constants. Escape characters are represented by a backslash (/) followed by a character or an octal or hexadecimal number.

Escape Character meaning ASCII code value (decimal)
/A bell (BEL) 007
/B backspace (BS) 008
/F form feed (FF) 012
/N line feed (LF) 010
/R press enter (CR) 013
/T horizontal tabulation (HT) 009
/V vertical tabulation (VT) 011
// Backslash 092
/? Question mark character 063
/'Single quotes character 039
/"Double quotation mark character 034
/0 null character (null) 000
/DDD any character three octal characters
/Xhh any character two hexadecimal

When single quotation marks and backslash are used in character constants and double quotation marks and backslash are used in character constants, escape characters must be used to represent them, that is, the backslash must be added before these characters.
Using escape characters/d Or/x H in C Programs can easily and flexibly express any character. /D is followed by a slash and followed by three Octal numbers. The value of the three Octal numbers is the corresponding octal a s c I code value. /X is followed by two hexadecimal numbers. The two hexadecimal numbers correspond to the hexadecimal a s c I code value of the character.

Note the following when using escape characters:
1) only lowercase letters can be used in escape characters. Each escape character can only be considered as one character.
2) The/V vertical tabulation and/F break have no impact on the screen, but will affect the printer's response.
3) when non-printable characters are used in C Programs, escape characters are usually used.

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? (Verify in Windows vc6 and TC2)

An escape character is a special character constant. The escape character starts with a backslash "/" and is followed by one or more characters. The escape character has a specific meaning. It is called an "escape" character because it is different from the original meaning of the character. For example, the "/N" used in the format string of the printf function in the previous examples is an escape character, and its meaning is "carriage return ". Escape characters are mainly used to indicate control codes that are not easily represented by general characters.
Common escape characters and their meanings
Meaning of escape characters

Broadly speaking, any character in the C language character set can be expressed by escape characters. In Table 2.2,/DDD and/xhh are proposed for this purpose. DDD and HH are both octal and hexadecimal ASCII codes. For example,/101 represents a word? Quot; a ",/102 indicates the letter" B ",/134 indicates the backslash,/xoa indicates the line feed, and so on. Use of escape characters
Void main ()
{
Int A, B, C;
A = 5; B = 6; C = 7;
Printf ("% d/n/T % d/n % d/T/B % d/N", A, B, C, A, B, c );
}
This program exercises the use of escape characters
A, B, and C are integers 5-> A, 6-> B, 7-> C
Call printf to display the program running result
Printf ("% d/n/T % d/n % d/T/B % d/N", A, B, C, A, B, c );
The program outputs a value 5 In the first column, which is "/N", so press enter to wrap the line, and then press "/t ", so I jumped to the next tabulation position (set the tabulation position to 8), and then output the B value 6; the empty two cells output the C value 7 and then "/N ", therefore, press enter to wrap the line. If the two cells are empty, the value is 5. If the three cells are empty, the B value is 6; next, "/t" jumps to the next tabulation position (6 alignment with the previous line), but the next escape character "/B" makes the return a grid, therefore, C value 7 is output next to 6.

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.