有关二维数组的问题

来源:百度知道 编辑:UC知道 时间:2024/06/12 05:13:01
int N=2;
char str_number[N][20]={"error","errorc2143"};
char str_describe[N][100]={"error","errorLNK2001"};
char str_analysis[N][200]={"error","语法错误,忘写“;”;"};

以下是系统的错误提示:
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0

急需高手指教!!

数组下标不能为变量

char str_number[2][20]={"error","errorc2143"};
char str_describe[2][100]={"error","errorLNK2001"};
char str_analysis[2][200]={"error","语法错误,忘写“;”;"};

或者
#define N 2 //定义一个宏

char str_number[N][20]={"error","errorc2143"};
char str_describe[N][100]={"error","errorLNK2001"};
char str_analysis[N][200]={"error","语法错误,忘写“;”;"};

数组定义时候 长度值必须是常量或者常量表达式

而您用的N是变量 所以错误了

改正一下即可

int n=2;
改为
const int n=2;
或者 使用预处理指示
#define N 2