strlen( )函数:
测试字符串实际长度的函数,它的返回值是字符串中字符的个数(不包含’\0’)
//strlen( )函数:测试字符串实际长度的函数,它的返回值是字符串中字符的个数(不包含’\0’) //模拟strlen( )函数功能 #include<stdio.h> #include<string.h> #include<stdlib.h> int my_strlen(char str[]) { int i = 0; while (str[i] != '\0') { i++; } return i; } int main() { char strHello[] = "hello world"; int nNum1, nNum2; nNum1 = strlen(strHello); nNum2 = my_strlen(strHello); printf("nNum1 = %d\r\nnNum2 = %d\r\n", nNum1, nNum2); system("pause"); return 0; }