c - 在函数调用中初始化 cstring 数组

标签 c cstring

我怎么能做到这一点:

char sXSongs[20][30] = {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"};
addAlbum(&list, "The Beatles", "Some Famous CD", 1960, sXSongs);

但不是这个:

addAlbum(&list, "The Beatles", "Some Famous CD", 1960, {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"});

是否无法在函数调用中初始化 cstrings 数组?

以下是一些其他信息:

album* list = NULL;
typedef struct album {
    char performer[20];
    char CDtitle[50];
    int year;
    char songs[20][30];
    struct album* prev;
    struct album* next;
} album;

最佳答案

没有。可以在声明数组时对其进行初始化,否则不行。

关于c - 在函数调用中初始化 cstring 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2271874/

相关文章:

c - 问:对于c程序员来说,str ="Hello"是否表示字符串复制?这背后的原因是什么?

c++ - 从 char 数组/cstring 中删除空格?

c++ - C++中不同字符串类型的优缺点

C:生成缓冲区

c++ - 在 g++ 编译器中使用 strlen 获取数组的长度

c - 我们如何分配内存以返回一个 char**

c - 我的自定义操作系统内核中的 VGA 显示问题

无法使用 MinGW 编译 C 代码

c - 如何使用结构在多线程中拥有共享计数器?

c++ - 将字符串转换为 unsigned char []