字符串的结束标志符是“ \0 ”,也就是空字符NULL(ascii 0x00),而不是空格(ascii 0x20),也不是0(ascii 0x30)
1 #include <stdio.h>
2 #include <string.h>
3
4 void main()
5 {
6 char str[50] = "hello world";
7 int i;
8
9 printf("sizeof str = %d\n",strlen(str));
10
11 for(i=0;i<15;i++)
12 printf("0x%0x ",str[i]);
13 printf("\n");
14
15 printf("a\nb\n");
16 printf("a\rb\n");
17 printf("a\tb\n");
18 }
ma@ma-virtual-machine:~/sample$ ./endstr
sizeof str = 11
0x68 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x0 0x0 0x0 0x0
a
b
b
a b
ma@ma-virtual-machine:~/sample$