C语言实现strlen函数和字符串遍历

来源:转载

strlen实现:

1 int my_strlen(char *str)2 {3 char *tmp = str;4 while (*str)5 {6 str++;7 }8 return str - tmp;

字符串遍历:

 1 void stringDis(char *str) 2 { 3 //int len = sizeof(str) / sizeof(char); //error if there is space 4 //int len = strlen(str); //<string.h> 5 int len = my_strlen(str); //same as strlen() 6 for (int i = 0; i < len;i++) 7 { 8 printf("%c", str[i]); 9 }10 printf("/n");11 }

分享给朋友:
您可能感兴趣的文章:
随机阅读: