gpt4 book ai didi

c - 为什么使用 C 的 Hew 中的错误 Expected a "}"

转载 作者:太空宇宙 更新时间:2023-11-04 06:21:03 25 4
gpt4 key购买 nike

char buffer[30]; 
char Days[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
GetTimeOfTheDay();

我在第二行收到错误,如预期的“}”。可能的原因是什么?有什么想法吗?

最佳答案

char Days[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

可以存储最多 6 个字符的一个 字符串(NUL 终止符+1)。使用二维数组修复它:

char Days[7][4] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

或使用指向char 的指针数组作为@BLUEPIXY suggested :

char *Days[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

请注意,如果您使用此方法,则不应修改字符串。

关于c - 为什么使用 C 的 Hew 中的错误 Expected a "}",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34959728/

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