c语言错误~直接照搬的到底哪里错了啊?

来源:百度知道 编辑:UC知道 时间:2024/05/18 05:33:59
#include <iostream>
int letter,digit,space,others;
int main()
{ int count(char str[]);
char text[80];
gets(text);
letter=0,digit=0,space=0,others=0;
count(text);
printf("letter:%d,digit:%d,space:%d,others:%d\n",letter,digit,space,others);
}
int count(char str[])
{ int i;
for(i=0;str[i]!='\0';i++)
if((str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z'))
letter++;
else if (str[i]>='0'&&str[i]<='9')
digit++;
else if (strcmp(str[i],'')==0)
space++;
else
others++;
}

输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
#include <stdio.h>
#include <math.h>
#include <conio.h>
main()
{
char c;
int letter=0,space=0,digit=0,other=0;
printf("Please input zi fu zu:"); /*请输入字符和空格还有数字等组成的串*/
while((c=getchar())!='\n')
{
if(c>='A'&&c<='Z'||c>='a'&&c<='z')
letter++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
other++;
}
printf("letter=%d\nspace=%d\ndigit=%d\nother=%d\n",letter,space,digit,other);
getch();
}
给你我的正确的。你的应该这样改。我经过wintc测试,运行正确。
#include <stdio.h>/*头文件是这个,你的错了*/
int letter,digit,space,others;
int main()
{ int count(char str[]);
char text[80];
gets(text);
letter=0,digit=0,space=0,others=0;
count(text);
printf("