编一函数int fun(int s[ ]),其功能是返回字符串s的长度

来源:百度知道 编辑:UC知道 时间:2024/09/24 05:28:51
考试题,急要,谢谢!!

改正:字符串一般为:char s[]而非int s[],函数原型为:int fun(int s[])
编译环境:VC6.0
#include <stdio.h>
int fun(char s[]){
if(!s[0]) return -1;
int i=0;
while(s[i]) ++i;
return i;
}
int main(){
char ar[] = "ascd";
printf("LEN:%d\n",fun(ar));
return 0;
}

wangsl1978:回答问题不负责任,死循环你都没看出来?

int fun(int s[ ])
{
int i=0,k=0;

while(s[i]!='\0')
k++;

return k;

}