about the escaper character in C programming language
来源:互联网 发布:淘宝拍a发b平台荷塘 编辑:程序博客网 时间:2024/05/16 07:57
forewords:
In the character set can be divided into two categories.
There is a class of characters can be displayed as characters, such as a, @, c, ^, #, and spaces and so on.
The other characters called control characters, is designed to control function, so called control characters.
In C, the escape character is used to indicate that the main character is not generally easy to use, said control code.
They can not find on the keyboard or a corresponding key (of course you can enter a special mode), or when the key is not after the characters on the display interface.
Escape character is a kind of "\" character, followed by a character or an octal (\ ddd) or hexadecimal (\ xhh) said.
Together with a backslash character after character to form a particular, specific meaning, different from the character of the original meaning (it is called the escape character).
1 followed by a character representation escape character, although in the form of two characters, but represent a character.General escape character is used:
\ a \ n \ t \ v \ b \ r \ f \ \ \ '\ "
Escape character '\ \' on behalf of the backslash "\" escape character '\'-character "'" and the escape character' \ "'representative character" ""
Is to show the character of its own, why should it escape it?
This is because the form of their original character as it has been used, in which the distinction between single quotes for character constants in parentheses, quotation marks used to distinguish the string (the following will be
Introduction string) brackets, and the backslash escape character itself is used to indicate the beginning, so they must be re-statement with the escape character.
2 octal and hexadecimal escape characters
They are the backslash '\', respectively, and the subsequent 1 to 3 octal digits or letters x (or X) and subsequent 1 to 2 hexadecimal digits consisting of a sequence of characters.
For example,
'\ 170', '\ 171', '\ 172' or '\ x78', '\ x79', '\ x7A', respectively, the character 'x', 'y', 'z'.
Because the character 'x', 'y' and 'z' of the ASCII code of octal values were 170, 171 and 172, respectively, hexadecimal value 0x78, 0x79, and 0x7A.
Characters using the octal and hexadecimal escape the escape character, not only that the control characters, but can also be said to display the character (if you wish).
However, due to different computer systems may use different character sets, so, in order to program portability, the program should be less use of this form of escape characters.the escaper character sets as following:
escaper charatcer
ASCII ( in Hexadecimal)
ASCII (in Decimal )
means
\0
0x00
0
NULL
\a
0x07
7
beep
\b
0x08
8
backspace
\t
0x09
9
horizontal tab
\n
0x0A
10
line feed
\v
0x0B
11
vertical tab
\f
0x0C
12
feed
\r
0x0D
13
carriage return
\"
0x22
34
double quotes
\'
0x27
39
single quotes
\?
0x3F
63
question mark
\\
0x5C
92
backslash
\ddd
\xhh
in fact ,
1. "\?" is equalvalent to "?" , and " \' " is equalvalent to " ' " as well, it seem that they have no need to do escape ;
2. if you want to print "%"(it' not a escaper character) in printf(), you should add extra special "%", in other words you shall use "%%" in the first parameter
(a string means the formatted outputprint ), otherwise , it's alert "segmentation fault" when run it (althought it pass the compiler).
it's the same as other series of print funciton , such as sprintf(). snprintf(), fprintf()...etc.
3. '\0' means the end of a string,if you use "strlen()" to count the character number of a string, it's end at "\0", and it excludes the character "\0";
/** escaper_char.c by vinco at 2011-09-03* Ubuntu CC/gcc-4.4.1*/#include<stdio.h>#include<string.h>int main(){char escaper_char[]="%'?\a\b\t\n\0\v\f\r\"\'\?\\";int i = 0;printf("escaper_char = %s\n",escaper_char);for(i = 0; i < sizeof(escaper_char); i++)printf("escaper_char[%d]\r = %d\n",i, escaper_char[i] );printf("\n");for(i = 0; i < strlen(escaper_char); i++)printf("escaper_char[%d] = %d\n",i, escaper_char[i] );printf("%d %%s\n",100);return(0);}
run it:
root@vinco:/home/vinco/c# make escaper_charcc escaper_char.c -o escaper_charroot@vinco:/home/vinco/c# ./escaper_charescaper_char = %'? = 37er_char[0] = 39er_char[1] = 63er_char[2] = 7per_char[3] = 8per_char[4] = 9per_char[5] = 10er_char[6] = 0per_char[7] = 11er_char[8] = 12er_char[9] = 13er_char[10] = 34er_char[11] = 39er_char[12] = 63er_char[13] = 92er_char[14] = 0per_char[15]escaper_char[0] = 37escaper_char[1] = 39escaper_char[2] = 63escaper_char[3] = 7escaper_char[4] = 8escaper_char[5] = 9escaper_char[6] = 10100 %sroot@vinco:/home/vinco/c#
- about the escaper character in C programming language
- about the character string in C language
- The C programming language
- the c programming language
- The C Programming Language
- The Swift Programming Language中文版 ----About Swift
- Programming in the Ruby language
- The amazing efficiency of pointer in C Programming Language
- 翻译《the c programming language》
- The C Programming Language--------(1)
- The C Programming Language 笔记
- 《The C Programming Language》笔记
- the C programming language 练习
- 翻译 The C programming language
- The C programming language 4.1
- <The C programming language> 5.2
- <The C programming language> 5.9
- <<The C programming Language>>推荐
- 再谈程序与书法
- z-index不起作用
- 程序员总结:帮助你早些明白一些道理
- 让你的程序快起来
- 压榨自己的学习能力极限,每天学习新内容之MySQL服务器!(三)(今天内容更新完结)
- about the escaper character in C programming language
- How To Create a Simple Magazine App with Core Text
- 中国电子商务产业预警:泡沫正在逼近
- 【分享】【计算器程序--java编写】
- 制作WINPE启动光盘的方法
- 介绍WinPE硬盘安装WINXP方法
- 在vb中如何应用报表
- Python的详细介绍
- 程序员怎样学数学