第15周OJ实践4 字符串长度

问题及代码:

Problem D: C语言习题 字符串长度

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1981   Solved: 1417
[ Submit][ Status][ Web Board]

Description

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

Input

一行字符串

Output

字符串长度

Sample Input

t9g(*&WE3@#$fw2adECWEr

Sample Output

22
代码一:

#include
#include
int main()
{
    int i=-1;
    int stringlen (char *);
    char str[100],s;
    s=str[100];
    int len;
    gets(str);
    len=stringlen(str);
    printf("%d\n",len);
    return 0;
}
 int stringlen (char * str)
{
    int i = 0;
    while (str[i]);
    i++;
    return i;

}

代码二:

#include
#include
int main()
{
    char a[100];
    int i= 0;
    gets(a);
    while(a[i] != '\0')  i++;
    printf("%d\n",i);
    return 0;
}
运行结果:

第15周OJ实践4 字符串长度_第1张图片

知识点总结:注意OJ平台给定主程序时,需要补充的函数的功能。

你可能感兴趣的:(第15周OJ实践4 字符串长度)