gpt4 book ai didi

c - C 中带数字的结构名称

转载 作者:行者123 更新时间:2023-11-30 20:54:48 24 4
gpt4 key购买 nike

我是 C 新手,我正在尝试创建一个结构来管理书籍:

typedef struct bookManagement{
char *name;
char *author;
char *country;
char *genre;
int year;
} book;

如何创建带有数字的结构名称,例如:

main(){
book 1={"The great Gatsby","F. Scott Fitzgerald","USA","novel",1925};
}

我的 IDE 报告了此语句的错误:

"[Error] expected identifier or '(' before numeric constant"

最佳答案

来自 Kernighan 和 Ritchie 的《C 编程语言》,第 35 页:

There are some restrictions on the names of variables and symbolic constants. Names are made up of letters and digits; the first character must be a letter.

所以你想要的是这样的:

typedef struct bookManagement{
char *name;
char *author;
char *country;
char *genre;
int year;
} book;

int main(){
book book1={"The great Gatsby","F. Scott Fitzgerald","USA","novel",1925};
}

如果你想对数字进行某种索引,我想你会想要使用结构数组。如果您需要更多信息,我建议您阅读 this guide因为它为可以完成的方法提供了一些不同的选项。祝学习顺利!

关于c - C 中带数字的结构名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37638639/

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