碎碎念(2)
目录
1.strlen()、sizeof()
strlen:测字符串长度,不包含数字0,字符'\0'
sizeof:测数组长度,包含数字0,字符'\0'
char buf1[ ] = "abc";
strlen(buf1) === 3
sizeof(buf1) === 4
char buf2[100] = "abc";
strlen(buf2) === 3
sizeof(buf2) === 100
2.c语言字符串,以字符'\0',数字0结尾
char buf[50] = {'a','b','c','0','d'};
printf("%s",buf); //abc0d
char buf1[50] = {'a','b','c','\0','d'};
char buf2[50] = {'a','b','c',0,'d'};
printf("%s %s",buf1,buf2); //abc
3.数组名是一个指针常量
原因:便于内存回收
4.利用strstr标准库函数找出一个字符串中substr出现的个数
5.两头堵模型返回新字符串
" abc " ==> "abc"