
效果包你满意, 亲~~~
#include
int length(char *s);
int main(void)
{
int len;
char str[80];
char ch;
do
{
printf("Enter string(whthin 80 characters): ");
gets(str);
len = length(str);
printf("输入字符串的长度为:%d\n"虚橘, len);
printf("\nDo you want continue y/n: \n");
scanf(" %c", &ch);
while ('\n' != getchar())
{
continue;
}
}while('y' == ch || 'Y' == ch);
printf("Bye\n"棚誉悄);
return 0;
}
int length(char *s)
{
int i=0;
int count = 0;//计数
while ('\0' != s[i])
{
count++;
i++;
}
return count;
}
测试结果:
Enter string(whthin 80 characters): fjalsjdlafjfalj ajsdf
输入字符链渣串的长度为:21
Do you want continue y/n:
y
Enter string(whthin 80 characters): jlsdjflsjafjw w jljsl
输入字符串的长度为:21
Do you want continue y/n:
y
Enter string(whthin 80 characters): jsljfljxooa sjldj
输入字符串的长度为:17
Do you want continue y/n:
n
Bye
Press any key to continue
假设以输入 END 作启团为结束。
#include <悄碰橘stdio.h>吵孝
int length(char *s);
int main(int argc, char *argv[])
{
int l;
char s[80]=;
do
{
gets(s);
l=length(s);
printf("Length=%d\n",l);
}while(strcmp(s,"END"));
return 0;
}
int length(char *s)
{
char *p=s;
int l=0;
while(*p!=NULL)
{
p++;
l++;
}
return l;
}
#include <毕燃简stdio.h>
int length(char *s)
{
手裤 int len = 0;
while (*(s + len) != ' ') len++;
return len;
}
int main()
{
char s[80] = {0};
while (1)
{
scanf("%s", s);
段正 printf("length = %d ", length(s));
}
return 0;
}
#include
int length(char *s){
int ret = 0;
while(*s++) ret++;
return ret;
}
int main(){
判衡char str[80];
while(scanf("%s",str) != EOF)
printf("length = %d ",length(str));
举冲数 正首 return 0;
}
#include激盯
int length(char *s)
{
int i;
for(i=0;s[i]!=' ';i++);
return i;
}
int main()
{
char str[80];
gets(str);
while(str[0]!=' ')
{
printf("%d ", length(str));
gets(str);
态戚 帆铅陵 }
}