我的C的程序报错,谁可以帮忙一下.谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/12 21:20:12
#include "stdio.h"
main()
{
char ch;
int letter=0,mun=0,other=0;
printf("请输入几个字符串");
scanf("s%",ch);
while(ch!='?')
{
if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z')
letter++;
else if(ch>='0'&&c<h='9')
mun++;
else
other++;
}
}
报错是ch定义以前使用了在main 函数中

#include "stdio.h"
main()
{
char ch;
int letter=0,mun=0,other=0;
printf("请输入几个字符串");
//scanf("%s",ch);
while((ch = getchar()) != '\n')
{
if(ch >='a'&&ch<='z'||ch>='A'&&ch<='Z')
letter++;
else if(ch >='0' && ch <= '9')
mun++;
else
other++;
}
printf("letter:%d\n", letter);
printf("munber:%d\n", mun);
printf("other:%d\n", other);
}

---------
这样就可以了,你的错误在以下几个方面
1.scanf("s%",ch);
是%s,不是s%;ch是字符型,不能输入字符串
2.else if(ch>='0'&&c<h='9')
c<h='9'这里写错了,应该是ch<='9'
3.没有输出,看不到结果

1. char ch -------- 改为char ch[]
char *cp = ch;
2. scanf("s%",ch) ---------