1

我正在尝试制作一个程序来显示用户订购的杂货。它会将数据写入另一个文件(完成后),并显示每个食物组的平均值。它是这样的:

#include<stdio.h>

int main()
{
    int beverage[3][20] = {
        "Soda"
        "Water"
        "Coffee"
    }; /* Here is 9 */
    int produce[3][20] = {
        "Apple"
        "Carrot"
        "Banana"
    }; /* Here is 14 */
    int dairy[3][20] = {
        "Milk"
        "Yogurt"
        "Cheese"
        }; /* Here is 19 */
    int dessert[3][20] = {
        "Ice Cream"
        "Cake"
        "Chocolate"
    }; /* Here is 24 */
    int meat[3][20] = {
        "Chicken"
        "Seafood"
        "Beef"
    }; /* Here is 29 */
    int grain[3][20] = {
        "Bread"
        "Muffin"
        "Cereal"
    }; /* Here is 34 */

    printf("Beverages: %p\n ", beverage[1]);
    printf("Produce: %p\n ", produce[2]);
    printf("Dairy: %p\n ", dairy[0]);
    printf("Candy: %p\n ", dessert[0]);
    printf("Meat: %p\n ", meat[2]);
    printf("Grain: %p\n ", grain[1]);

    return 0;
}

它在第 9、14、19、24、29 和 34 行显示错误消息“从非宽字符串初始化的宽字符数组”。那么,错误消息对我的代码意味着什么?如何更改它以及在哪里更改?

4

1 回答 1

6

如果您想要的是字符串列表(我假设这是您想要的)。您应该使用char而不是int

char beverage[3][20] = {
    "Soda",
    "Water",
    "Coffee"
};
于 2012-10-07T17:54:45.600 回答