我正在尝试执行以下操作,但是编译器抱怨括号,但是,找不到替代方法。
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 - C:使用字符串数组初始化结构,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16505880/