aer*_*aer 5 c multidimensional-array turbo-c
我将问下面提供的有关我的代码的问题......我的问题是在哪里有评论/*This line*/.我使用变量y和x:y表示HEIGHT,x表示WIDTH.我第一次运行该程序时,代码scanf("%d,%d", &y, &x);却很遗憾,程序运行不正常.但是当我用这个修改代码时scanf("%d,%d", &x, &y);,我能够依次运行程序.我无法理解它是如何发生的,因为我将y设置为HEIGHT,将x设置为WIDTH?
File Edit Run Compile Project Options Debug Break/watch
????????????????????????????????????? Edit ?????????????????????????????????????
? Line 1 Col 43 Insert Indent Tab Fill Unindent * C:NONAME.C ?
?#define HEIGHT 5 ?
?#define WIDTH 10 ?
? ?
?char enemy[HEIGHT][WIDTH]= ?
? { {0,0,0,0,0,0,0,0,0,0}, ?
? {0,1,1,0,0,1,0,0,0,0}, ?
? {0,0,0,1,0,1,0,1,1,0}, ?
? {0,0,0,0,0,0,0,0,1,1}, ?
? {0,0,1,1,0,1,0,0,0,1} }; ?
? ?
?main() ?
?{ ?
? char friend[HEIGHT][WIDTH]; ?
? int x,y; ?
? ?
? clrscr(); ?
? ?
? for(y=0; y<HEIGHT; y++) |
| for(x=0; x<WIDTH; x++) |
| friend[y][x]='.'; |
| |
| while(x >= 0) |
| { |
| for(y=0; y<HEIGHT; y++) |
| { |
| for(x=0; x<WIDTH; x++) |
| printf("%c", friend[y][x]); |
| printf("\n"); |
| } |
| |
| printf("Coordinates: "); |
| scanf("%d,%d", &x, &y); /*This line*/ |
| |
| if(enemy[y][x] == 1) |
| friend[y][x]="\xDB"; |
| else |
| friend[y][x]="\xB0"; |
| } |
|} ?
???????????????????????????????????? Watch ?????????????????????????????????????
? ?
????????????????????????????????????????????????????????????????????????????????
F1-Help F5-Zoom F6-Switch F7-Trace F8-Step F9-Make F10-Menu NUM
Run Code Online (Sandbox Code Playgroud)