C++程序设计语言练习6.10 字符串函数的写法

来源:互联网 发布:卡斯特的复仇知乎 编辑:程序博客网 时间:2024/05/16 08:13

自己写的strlen和strcpy:

unsigned int strlen(const char *s){unsigned int count = 0;while(*s++ != '\0')count++;return count;}char * strcpy(char *dest,const char *res){while(*res != '\0')*dest++ = *res++;return dest;}

抄写的strcmp答案:

int strcmp(char const* first,char const* second){do{int diff = *first - *second;if (diff){return diff;}}while(*(first++) && *(second++))return 0;}


0 0
原创粉丝点击