编程实现计算字符串的长度

来源:互联网 发布:安卓软件搜索 编辑:程序博客网 时间:2024/06/04 00:32

strcpy库函数的实现细节

#include <stdio.h>#include <assert.h>int strlen1(const char* src){    assert(NULL!=src);    int len = 0;    while(*src++!='\0')        len++;    return len;}int strlen2(const char *src){    assert(NULL!= src);    const char *temp = src;    while(*src++!='\0');      return (src-temp -1);}int main(){    char p[] = "Hello world!";    printf("%d\n",strlen1(p));  //12    printf("%d\n",strlen2(p)):  //12    return 0;}   
原创粉丝点击