编写一个程序实现strlen函数的功能

写自己的 strlen 函数-----→ mystrlen

 1 #include <stdio.h>
 2 #include <string.h>
 3 #define N 100
 4 
 5 int mylen(char *s)
 6 {
 7     //数组型 
 8 //    int cnt = 0;
 9 //    while(s[cnt] != '') {
10 //        cnt++;
11 //    }
12 
13 //    return cnt;
14 
15     //指针型
16     char *p = s;
17     while(*s != '') {
18         s++;
19     }
20 
21     return s - p;
22 }
23 
24 int main()
25 {
26     char s[100];
27 //  gets(s);                    
28     fgets(s, N, stdin);                 //(gets和fgets函数的区别29     if(s[strlen(s) - 1] == '
') {      // 去掉换行符
30         s[strlen(s) - 1] = '';   
31     }
32     printf("%d", mylen(s));
33     
34     return 0;
35 } 
原文地址:https://www.cnblogs.com/aexin/p/3884844.html