C二维数组

问题描述

| 我要问一些下面提供的代码...我的问题是在注释“ 0”的那一行。我使用变量y和x:y代表高度,x代表宽度。我第一次运行该程序时,代码是
scanf(\"%d,%d\",&y,&x);
,但不幸的是,该程序无法正常运行。但是,当我用
scanf(\"%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,1,1},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,&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
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)