C 编写函数统计字符串长度
这个函数貌似挺能让人接受的OTZ……功能与
<string.h>
里的strlen()
功能一模一样
1int strlen(char s[])
2{
3 int i;
4
5 i = 0;
6 while (s[i] != '\0')
7 ++i;
8 return i;
9}
10
这种类型的代码我们已经屡见不鲜了吧
随手记录自己的学习过程
这个函数貌似挺能让人接受的OTZ……功能与
<string.h>
里的strlen()
功能一模一样
1int strlen(char s[])
2{
3 int i;
4
5 i = 0;
6 while (s[i] != '\0')
7 ++i;
8 return i;
9}
10
这种类型的代码我们已经屡见不鲜了吧
评论 (1)
借用一下 **《C算法》** 一节中的代码 ```c strlen(a) b=a; while (*b++); return b-a-1; strcpy(a, b) while(*a++ = *b++); strcat(a, b) strcpy(a+strlen(a),b); strcmp(a, b) while(*a++ == *b++) if (*(a-1) == 0) return 0; return *(a-1) - *(b-1); ```
=A=这些函数我一个都没见过 还没有看到这里