写一个函数,求一个字符串的长度,在main 函数中输入字符串,并输出其长度。

// 写一个函数,求一个字符串的长度,在main 函数中输入字符串,并输出其长度。
#include <stdio.h>
main()
{
 int len;
 char*str[20];
 printf("please input a string:\n");
 scanf("%s",str);
 len=length(str);//访问length函数形式变量str
 printf("the string has %d characters:",len);
 return 0;
}
length(p)
char *p;
{int n;//用于计数
n=0;
while("p!='\0'")
{n++;
p++;
}
return n;
}

猜你喜欢

转载自blog.csdn.net/singularityfisher/article/details/80524562