|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
void main()
{
int i,j,a=0,b=0,c=0,d=0,e=0;
char a[3][80]={
{"Hello Jack, what time is it? It is 16:50."},
{"This is a array test progam."},
{"I have finished it, bye-bye."}
};
for (i=0;i<3;i++)
{
for (j=0;j<80;j++)
{
if (a[i][j]>='a'&&a[i][j]<='z')
a++;
else if (a[i][j]>='0'&&a[i][j]<='9')
b++;
else if (a[i][j]==' ')
c++;
else if (a[i][j]>='A'&&a[i][j]<='Z')
d++;
else
e++;
}
}
printf("小写字母有%d个\n",a);
printf("数字有%d个\n",b);
printf("大写字母有%d个\n",d);
printf("空格有%d个\n",c);
printf("其他字符有%d个\n",e);
}
代码如上,
[Error] conflicting types for 'a' 这是char那行的错误;
[Error] lvalue required as increment operand 这是a++那一行,我用的是dev c++,求解答!!!
标识符冲突,变量 a 的定义有矛盾
int i,j, a=0,b=0,c=0,d=0,e=0;
char a[3][80]={
代码已经调好了,谨供楼主参考 #include<stdio.h>
int main(void)
{
int i , j , b , c , d , e , f ;
char a[][80] = {
{"Hello Jack, what time is it? It is 16:50."} ,
{"This is a array test progam."} ,
{"I have finished it, bye-bye."}} ;
for(b = c = d = e = f = i = 0 ; i < 3 ; i ++) {
for(j = 0 ; a[i][j] ; j ++) {
if(a[i][j] >= 'A' && a[i][j] <= 'Z') b ++ ;
else if(a[i][j] >= 'a' && a[i][j] <= 'z') c ++ ;
else if(a[i][j] >= '0' && a[i][j] <= '9') d ++ ;
else if(a[i][j] == ' ') e ++ ;
else f ++ ;
}
}
printf("大写字母有 %d 个\n" , b) ;
printf("小写字母有 %d 个\n" , c) ;
printf("数字有 %d 个\n" , d) ;
printf("空格有 %d 个\n" , e) ;
printf("其他字符有 %d 个\n" , f) ;
}
编译、运行实况 D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
大写字母有 5 个
小写字母有 63 个
数字有 4 个
空格有 17 个
其他字符有 8 个
D:\00.Excise\C>
|
|