Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/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
C 字符常量对于其类型太长_C_Variables - Fatal编程技术网

C 字符常量对于其类型太长

C 字符常量对于其类型太长,c,variables,C,Variables,代码: 我是c语言编程新手,我只是想制作一个字符串数组,但我得到了如下警告。谁能告诉我为什么会这样。这是一个c程序 char menu_list[] = {'Boiled egg', 'Corn flakes', 'Gobi 65', 'Chicken 65', 'Basandi'}; 您应该对字符串lliteral使用双引号,并且您错误地声明了数组 也许你在找这个 main_menu.c:226: warning: large integer implicitly truncated to

代码:

我是c语言编程新手,我只是想制作一个字符串数组,但我得到了如下警告。谁能告诉我为什么会这样。这是一个c程序

char menu_list[] = {'Boiled egg', 'Corn flakes', 'Gobi 65', 'Chicken 65', 'Basandi'};

您应该对字符串lliteral使用双引号,并且您错误地声明了数组

也许你在找这个

main_menu.c:226: warning: large integer implicitly truncated to unsigned type
main_menu.c:226:36: warning: character constant too long for its type

char menu_list[]
更改为
char*menu_list[]
,并使用
“煮蛋”
而不是
“煮蛋”

最后的代码应该是

char *menu_list[] = {"Boiled egg", "Corn flakes", "Gobi 65", "Chicken 65", "Basandi"};

这是一个字符数组。试试
char*menu\u list[]
这是一个指向char的指针数组,也就是一个“string”数组。为了补充Thomas所说的,单引号的含义与双引号不同。我想知道这是否不在那个教程中(提示:它可能是)<代码>'foo'与
'foo'
不同。非常感谢各位。这是一个有价值的评论和建议。
“煮蛋”
是一个多字符常量。它有一个实现定义的值。这样的常量很少有用。所有未指定维度的2D数组将无法编译。@H2CO3编辑……出于java习惯……这不需要,我已经习惯了……对不起
char *menu_list[] = {"Boiled egg", "Corn flakes"};