gpt4 book ai didi

c++ - 灵活数组成员的使用无效

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:45:39 30 4
gpt4 key购买 nike

<分区>

我在编程时遇到了问题。

struct skills {
int SnCrypt;
char* Soutput;
int Soptind;
int Sdecrypt;
int Sargc;
char* Spassword;
char *const Sargv[];
};

struct skills* initSkills(int nCrypt, char* password, char *const argv[], char* output, int optind, int decrypt, int argc) {
struct skills* skill;
skill->SnCrypt = nCrypt;
skill->Spassword = password;
skill->Sargv = argv;
skill->Soutput = output;
skill->Soptind = optind;
skill->Sdecrypt = decrypt;
skill->Sargc = argc;

return skill;
}

gcc 告诉我

invalid use of flexible array member

对于行 skill->Sargv = argv;

我不明白如何用另一个指针指向 char *const argv[] 指向的值?我知道我肯定必须 malloc skill->Sargv 指针,但是怎么做呢?像这样 (char const*)malloc(sizeof(argv[]))?

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