#include <stdio.h>
#include <string.h>
/* utf-8 */
#define UTF_V "\342\224\202" /* U+2502, Vertical line drawing char */
#define UTF_VR "\342\224\234" /* U+251C, Vertical and right */
#define UTF_H "\342\224\200" /* U+2500, Horizontal */
#define UTF_UR "\342\224\224" /* U+2514, Up and right */
#define UTF_HD "\342\224\254" /* U+252C, Horizontal and down */
#define VT_BEG "\033(0\017" /* use graphic chars */
#define VT_END "\033(B" /* back to normal char set */
#define VT_V "x" /* see UTF definitions above */
#define VT_VR "t"
#define VT_H "q"
#define VT_UR "m"
#define VT_HD "w"
static struct {
const char *empty_2; /* */
const char *branch_2; /* |- */
const char *vert_2; /* | */
const char *last_2; /* `- */
const char *single_3; /* --- */
const char *first_3; /* -+- */
} sym_ascii = {
" ", "|-", "| ", "`-", "---", "-+-"},
sym_utf = {
" ",
UTF_VR UTF_H,
UTF_V " ",
UTF_UR UTF_H, UTF_H UTF_H UTF_H, UTF_H UTF_HD UTF_H},
sym_vt100 = {
" ",
VT_BEG VT_VR VT_H VT_END,
VT_BEG VT_V VT_END " ",
VT_BEG VT_UR VT_H VT_END,
VT_BEG VT_H VT_H VT_H VT_END, VT_BEG VT_H VT_HD VT_H VT_END},
*sym = &sym_ascii;
void escape(void)
{
printf("%s:\n", UTF_V); // │
printf("%s:\n", UTF_VR); // ├
printf("%s:\n", UTF_H); // ─
printf("%s:\n", UTF_UR); // └
printf("%s:\n", UTF_HD); // ┬
printf("%s:\n", VT_BEG); //
printf("%s:\n", VT_END); //
printf("%s:\n", VT_V); // x
}
int main()
{
char a = '\61'; // 字符1
char b = '\141'; // 字符a
char c = '\x31'; // 字符1
char d = '\x61'; // 字符a
char *e = "\61\141";
char *str1 = "\x31\x32\x33\x61\x62\x63"; // 字符串"123abc"
char *str2 = "\61\62\63\141\142\143"; // 字符串"123abc"
char *str3 = "The string is: \61\62\63\x61\x62\x63"; // 混用八进制和十六进制形式
printf("%ld\n", strlen("abc")); // 3
printf("%ld\n", strlen("t\328\t")); // 4, \t、\32被解释为转义字符,算一个字符
printf("%s\n", "t\328\t\61"); // "t8 1" , \32为空
#if 1
printf("%c %c %c %c\n", a, b, c, d); // 1 a 1 a
printf("%ld\n", strlen(e)); // 2
printf("[%s] [%s] [%s]\n", str1, str2, str3); // [123abc] [123abc] [The string is: 123abc]
printf("%ld\n", strlen(str1)); // 6
#endif
escape();文章来源:https://www.toymoban.com/news/detail-708086.html
return 0;
}文章来源地址https://www.toymoban.com/news/detail-708086.html
到了这里,关于c语言转义字符例子的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!