#include <stdio.h>
#include <stdlib.h>
int main ()
{
int len;
char*str=(char*)malloc(20*sizeof(char));//不知道你用的什么编译器,我用的VC6.0是不能char*str[20]这样定义的
//他的意思是定义一个char指针变量,给它20个空间的大小,但是下面用的时候会转换不了,所以我动态申请20个char的大小的空间
int length(char *);//你想在下面使用length(),这里就要先声明,告诉它有这个函数,要不然找不到
//或者你把length()函数放在主函数之前就不需要加这一句了。
printf("please input a string:\n");
scanf("%s",str);
len=length(str);
printf("the string has %d characters.\n",len);
return 0;
}
//你函数返回的是int型的n,所以函数的返回值要是int型的,不写的话在VC6.0中是不行的,TC中不知道
int length(char *p)//我估计你是用的TC,VC6.0貌似不允许你那种写法,不过意思都是一样的
{
int n;
n=0;
while(*p!='\0')
{
n++;
p++;
}
return n;
}