Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 设置一次时,二维数组中的值显示两次_Arrays_C_Multidimensional Array - Fatal编程技术网

Arrays 设置一次时,二维数组中的值显示两次

Arrays 设置一次时,二维数组中的值显示两次,arrays,c,multidimensional-array,Arrays,C,Multidimensional Array,我有一个包含字符的2D数组,但当我更改其中一个值时,它会在数组中的两个不同点上更改 我目前的代码是: #包括 #包括 #包括 #定义宽度100 #定义高度50 #定义阴影“*#@” 无效打印显示(字符显示[宽度][高度]) { 系统(“cls”); 对于(int y=0;y

我有一个包含字符的2D数组,但当我更改其中一个值时,它会在数组中的两个不同点上更改

我目前的代码是:

#包括
#包括
#包括
#定义宽度100
#定义高度50
#定义阴影“*#@”
无效打印显示(字符显示[宽度][高度])
{
系统(“cls”);
对于(int y=0;y
运行此代码会为我生成以下结果:

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
..................................................@.................................................

@FOR循环中有一个错误。您访问的
[y,x]
指向错误的方向

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define WIDTH 100
#define HEIGHT 50

#define SHADE " .*#@"

void print_display(char disp[WIDTH][HEIGHT])
{
    system("cls");

    for (int y = 0; y < WIDTH; y++) {
        for (int x = 0; x < HEIGHT; x++)
            printf("%c", SHADE[disp[y][x]]);

        printf("\n");
    }
}

int main()
{
    char disp[WIDTH][HEIGHT];
    memset(&disp, 1, WIDTH * HEIGHT);

    disp[49][0] = 4;

    print_display(disp);
    
    return 0;
}
#包括
#包括
#包括
#定义宽度100
#定义高度50
#定义阴影“*#@”
无效打印显示(字符显示[宽度
char disp[100][50]; 
for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++)
            printf("%c", SHADE[disp[y][x]]);
arr[3][4]:

        _________________
arr[0]: |0,1|0,2|0,3|0,4|    <-- sub-array at index 0 with 4 elements
        -----------------
        _________________
arr[1]: |1,1|1,2|1,3|1,4|    <-- ""        at index 1 ""
        -----------------
        _________________
arr[2]: |2,1|2,2|2,3|2,4|    <-- ""        at index 2 ""
        -----------------