Problem C: 指针:自定义函数length,调用它计算字符串的长度
Time Limit: 1 Sec Memory Limit: 64 MB
Submit: 14772 Solved: 10178
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 length(char *s);
int main()
{
char s[85];
while (gets(s) != NULL)
{
printf("%d\n",length(s));
}
return 0;
}
int length(char *s)
{
int i;
for ( i = 0;s[i] != '\0';i++);
return i;
}