代码实现
int mystrlen(char * str){
if(NULL == str){
printf("mystrcpy param error\n");
return 0;
}
char * c = NULL;
int len = 0;
c = str;
while(*c++ != '\0'){
len++;
}
return len;
}
void testmystrlen(void){
int len = 0;
char * src = "Hello World!";
printf("\n************ mystrlen ************ \n");
len = mystrlen(src);
printf("len = %d\n", len);
return;
}
代码编译
gcc main.c str.c -g -o a.exe
调试输出
************ mystrlen ************
len = 12