我有一个二维数组,我想通过一个函数
char blendModeOptions[18][16]={"Normal","Darken","Multiply","Color Burn","Linear Burn","Lighten","Screen","Color Dodge","Linear Dodge","Overlay","Soft Light","Hard Light",
"Vivid Light","Linear Light","Pin Light","Difference","Exclusion","Hue"};
blendMode = KIT_CreateSelectOption(blendModeOptions,18,&blendModeRect);
,函数的声明为:
KIT_SelectOption * KIT_CreateSelectOption(char ** options,int size ,SDL_Rect * rect);
我收到警告:
note: expected 'char **' but argument is of type 'char (*)[16]'
在函数内部,我通过此参数int KIT_AddOption(KIT_SelectOption *box, const char * option);
调用函数KIT_AddOption(box,options[i]);
当我在KIT_AddOption
的这一行代码中时,我的程序崩溃了
strcpy(opt->name,option);
我尝试使用char * option[16]
代替了char ** option
,但是它不起作用。
答案 0 :(得分:7)
您需要将数组定义为指针数组,而不是2D char数组。
char *blendModeOptions[]={"Normal","Darken","Multiply","Color Burn","Linear Burn","Lighten","Screen","Color Dodge","Linear Dodge","Overlay","Soft Light","Hard Light",
"Vivid Light","Linear Light","Pin Light","Difference","Exclusion","Hue"};