您的位置:首页 > 编程语言 > C语言/C++

strcpy 和strlen函数的模拟实现

2017-04-23 13:24 369 查看
//strcpy函数的模拟实现
#include<stdio.h>
#include<assert.h>
void my_strcpy(char *dest,char *src)
{
assert(dest!=NULL);
assert(src!=NULL);
while(*(dest++)=*(src++))
{
;
}
}
int main()
{
char arr[20];
my_strcpy(arr,"hello world");
printf("%s\n",arr);
return 0;
}
//strlen函数的模拟实现
#include<stdio.h>
#include<assert.h>
int my_strlen(char*dest)
{
int count=0;
assert(dest!=NULL);
while((*dest)!='\0')
{
count++;
dest++;
}
return count;

}

int main()
{
int ret=my_strlen("abcdef");
printf("ret=%d\n",ret);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言 函数
相关文章推荐