C 编写函数统计字符串长度

这个函数貌似挺能让人接受的OTZ……功能与<string.h>里的strlen()功能一模一样

int strlen(char s[])
{
    int i;

    i = 0;
    while (s[i] != '\0')
        ++i;
    return i;
}

这种类型的代码我们已经屡见不鲜了吧

植入部分

如果您觉得文章不错,可以通过赞助支持我。

如果您不希望打赏,也可以通过关闭广告屏蔽插件的形式帮助网站运作。

标签: 代码段

已有 4 条评论

  1. raidou

    借用一下 《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);
    1. =A=这些函数我一个都没见过 还没有看到这里

      1. raidou

        函数字面上的意思
        length
        copy
        concatenate
        compare

        = = 吃掉的格式...
        whie和strcmp(a,b)都打错了.

        1. 咳咳 现在被我设置成支持markdown的了OTZ

添加新评论