gpt4 book ai didi

C:用字符串数组初始化结构

转载 作者:行者123 更新时间:2023-12-02 02:02:34 25 4
gpt4 key购买 nike

我正在尝试执行以下操作,但编译器提示有括号,但是,我找不到替代方法。

struct cards {
char faces[13][6], suits[4][9];
}

typedef struct cards cards;

void init_struct(cards *s) {
s->suits = {"hearts","spades","clubs","diamonds"};
s->faces = {"ace","two","three","four","five",
"six","seven","eight","nine"
"ten","jack","queen","king"};
}

我意识到那里有几个可能重复的线程,但没有一个让我走上正轨。我希望你们中的一个能 :) 谢谢

最佳答案

#include <string.h>

typedef struct cards {
char faces[13][6], suits[4][9];
} cards;

cards base_card = {
{"ace","two","three","four","five",
"six","seven","eight","nine", //forgot "," at nine after
"ten","jack","queen","king"},
{"hearts","spades","clubs","diamonds"}
};

void init_struct(cards *s) {
memcpy(s, &base_card,sizeof(cards));
}

关于C:用字符串数组初始化结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16505880/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com