/*7.18.模拟实现strcpy,strlen*/
#include<stdio.h>
#define M 255
char* my_strcpy( char* arr, const char *p)//const确保不会改变p值
{
char* cp = arr;//定义一个指向数组的指针
if(*p==NULL)
printf("src is null\n");
while(*cp++=*p++)
{
;
}
return arr;
}
int * my_strlen( char src[ M])//char*和char[]做形式参数没有区别
{
int count=0;
while(*src++!='\0')
{
count++;
}
return count;
}
int main()
{
char arr[M];
char *src="abcdef";
printf("%s\n",my_strcpy( arr, src));
printf("%d\n",my_strlen(src));
system("pause");
return 0;
}
C语言编写strcpy和strlen函数
最新推荐文章于 2022-10-03 22:42:48 发布