Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.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_Arrays_Pointers - Fatal编程技术网

C 初始化字符串值的向量

C 初始化字符串值的向量,c,arrays,pointers,C,Arrays,Pointers,我试图创建一个字符串数组,它位于一个结构内部,但在语法方面有点问题。这是我的代码: typedef struct data_players { int id; int hp; //start = 20, Max = 30 int wght; // Max = 20 int atk; int def; char *inventory[20] = { inventory[0] = "knife"; inventory[1

我试图创建一个字符串数组,它位于一个结构内部,但在语法方面有点问题。这是我的代码:

typedef struct data_players {
    int id;
    int hp; //start = 20, Max = 30
    int wght; // Max = 20
    int atk;
    int def;
    char *inventory[20] = {
        inventory[0] = "knife";
        inventory[1] = "healthpack";
    }
} jogador;

不能在
struct
定义中赋值,也不能将
typedef
s指定给实例;它们是类型的别名。 比如:

typedef struct data_players
{
    int id;     
    int hp; //start = 20, Max = 30
    int wght; // Max = 20
    int atk;
    int def;
    char *inventory[20];
} data_players;
然后,您可以执行以下操作:

data_players jogador = {0, 20, 15, 5, 5, {"knife", "healthpack", /* ... */}};
使用指定的初始值设定项,您可以执行以下操作:

data_players jogador = {.inventory = {"knife", "healthpack", /* ... */}};

不要认为它解决了问题只有一件事,如果我得到的不是一个玩家,而是一个玩家数组,那么玩家[I]={.inventory={“刀子”、“健康包”、/*…*/};工作