C语言 字符常量对于其类型来说太长
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17036543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Character constant too long for its type
提问by GoSmash
Code:
代码:
char menu_list[] = {'Boiled egg', 'Corn flakes', 'Gobi 65', 'Chicken 65', 'Basandi'};
Am a new to c programming i just wanted to make an array of string, but am getting an waring as below. can anyone please tell me why its happening. Its a c program.
我是 C 编程的新手,我只想制作一个字符串数组,但我收到了如下警告。谁能告诉我为什么会这样。它的交流程序。
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
回答by pinkpanther
You should use double quotes for string lliteral, and you are wrongly declaring the array.
您应该对字符串 lliteral 使用双引号,并且您错误地声明了数组。
Perhaps you are looking for thiss.
也许你正在寻找这个。
char *menu_list[] = {"Boiled egg", "Corn flakes", "Gobi 65", "Chicken 65", "Basandi"};
回答by X Zhang
Change char menu_list[]to char * menu_list[]and use "Boiled egg"rather than 'Boiled egg'.
更改char menu_list[]到char * menu_list[]和使用"Boiled egg",而不是'Boiled egg'。
The final code should look like
最终代码应如下所示
char *menu_list[] = {"Boiled egg", "Corn flakes"};

