长话短说,我正在制作这个 3D OpenGL 构建器游戏。细节并不重要,但这是我的问题。我有这个字符串数组:
char building_category_names_UPPER_CASE[][30] = { "NOTHING", "WAREHOUSE", "PROCESSING PLANT", "FACTORY", "OFFICE" };
Run Code Online (Sandbox Code Playgroud)
我试图将它们传递给一个函数,该函数接受字符串数组形式的“列表”,并通过 Create_Button 方法为该列表中的每个项目创建按钮。
void Create_Button_List(char** list, int list_size, char* group_name, int pos_x, int pos_y)
{
for (int i = 1; i < list_size; i++)
{
char name[50];
strcpy(name, list[i]);
char group[50];
strcpy(group, group_name);
Create_Button(name, group, pos_x, i * pos_y, 205, 50, text_color_white, bg_color, text_color_white, bg_color_hover);
}
}
Run Code Online (Sandbox Code Playgroud)
但即使 VS 在构建时没有给我任何错误,当它到达 strcpy (name, list[i]); 时我仍然收到访问冲突错误。部分。
这里有什么问题?这不是我应该如何传递二维字符数组吗?或者是我将其传递给 strcpy 的方式有问题?需要明确的是,在本例中 list_size 为 5,所以这是正确的,问题不应该是 for 循环越界。
如果有人可以帮助我,请提前致谢!
c pointers multidimensional-array implicit-conversion function-declaration