Problem C: 指针:自定义函数length,调用它计算字符串的长度
Description
自定义一个函数int length(char *s),函数返回字符串s的长度。在main函数中输入字符串(长度小于80),调用该函数并输出其长度
Input
多组测试数据,每组输入一个任意字符串(长度小于80)
Output
输出字符串长度
Sample Input
hello
I like music.
oh, my god!
Sample Output
5
13
11
#include<stdio.h>
int main()
{
int length(char*s);
char s[80];
while(gets(s)!=NULL)
{
int t;
t=length(s);
printf("%d\n",t);
}
return 0;
}
int length(char*s)
{
int i,count;
while(*s!='\0')
{
*(s++);
count++;
}
return count;
}