画图函数中switch中出现非法case 什么意思啊
程序代码:
#include <stdio.h> #include <stdlib.h> #include <conio.h> #define n 10//地图大小 #define x 3//箱子数 #define y 2//位置 #define b 5//箱子 #define r 7//人 int a[n][n]={ {9,9,9,9,9,9,9,9,9,9}, {9,8,1,1,1,1,9,y,y,9}, {9,1,9,1,1,1,9,1,1,9}, {9,1,9,1,y,9,9,1,1,9}, {9,1,1,1,1,1,b+1,1,1,9}, {9,1,1,1,1,b+1,1,1,1,9}, {9,1,1+b,1,1,1,9,1,1,9}, {9,1,1,1,1,1,1,9,1,9}, {9,1,1,1,1,1,1,9,1,9}, {9,9,9,9,9,9,9,9,9,9} }; int cont; void move(int m,int g,int i,int j);//移动函数 void huatu(int a[n][n]);//画图 int main(void) { char ch; int m=2; int g=2; huatu(a); while(1) { fflush(stdin); ch=getch(); switch(ch) { case 'w': move( m, g,-1,0);break; case 's': move( m, g,1,0);break; case 'a': move( m, g,0,-1);break; case 'd': move( m, g,0,1);break; }; huatu(a); if(cont==x) printf("成功\n");}; return 0; } void move(int m,int g,int i,int j) { if(a[m+i][g+j]==9)//撞墙 a[m][g]=r+1; else if(a[m+i][g+j]==b+1&&a[m+2*i][g+2*j]==9)//箱子撞墙 a[m][g]=r+1; else if(a[m+i][g+j]==b+1&&a[m+2*i][g+2*j]==y)//箱子入位子 { a[m][g]-=r; a[m+i][g+j]-=b; a[m+i][g+j]+=r; a[m+2*i][g+2*g]+=b; m+=i; g+=j; } else if(a[m+i][g+j]==b+1&&a[m+2*i][g+2*j]==1)//推动箱子 { a[m][g]-=r; a[m+i][g+j]-=b; a[m+i][g+j]+=r; a[m+2*i][g+2*j]+=b; m+=i; g+=j; } else {a[m][g]-=r; a[m+i][g+j]+=r; m+=i; g+=j; } } void huatu(int a[n][n]) { int cont=0; int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) { if(a[i][j]==b+y) {cont++;} switch (a[i][j]) case 9:printf("■");break; case 8:printf("◎");break; case 5:printf("◇");break; case y:printf("○");break; case y+b:printf("※");break; case r+y:printf("※");break; default printf("□"); }; //return cont; }
C:\Documents and Settings\Administrator\桌面\111\ccc.c(88) : error C2046: illegal case
C:\Documents and Settings\Administrator\桌面\111\ccc.c(89) : error C2046: illegal case
C:\Documents and Settings\Administrator\桌面\111\ccc.c(90) : error C2046: illegal case
C:\Documents and Settings\Administrator\桌面\111\ccc.c(91) : error C2046: illegal case
C:\Documents and Settings\Administrator\桌面\111\ccc.c(92) : error C2046: illegal case
C:\Documents and Settings\Administrator\桌面\111\ccc.c(93) : error C2146: syntax error : missing ':' before identifier 'printf'
C:\Documents and Settings\Administrator\桌面\111\ccc.c(93) : error C2047: illegal default
执行 cl.exe 时出错.