上面的错误是由于函数缺少返回值的原因,修改后的程序如下:
int main()
{
{
int character, space, number, other; //定义变量 character, space, number, other分别为英文字符, 空格,数字,其他字符;
char all;
character=0;
space=0 ;
number=0 ;
other=0;
printf("please input a string : ");
scanf("%c",&all);
while (all!='\n')
{
if((all>='a'&&all<='z')||(all>='A'&&all<='Z'))
character=character+1;
else
{
if ((all>=0)&&(all<=9))
number=number+1;
else
if(all=='sp')
space=space+1;
else
other=other+1;
}
scanf ("%c",&all);
}
printf("the number of engilsh characters , spaces, numbers,other characters are %d, %d, %d, %d ",character,space,number,other);//另外此处应该去掉变量前的&,才能输出正确结果.
}
return 0;
}
希望能够帮助你解决问题.