gpt4 book ai didi

c - ansi-c : assignment makes integer from pointer without cast

转载 作者:行者123 更新时间:2023-12-04 05:14:40 24 4
gpt4 key购买 nike

我正在尝试更多地了解 C,我想知道是否有人可以澄清这里发生了什么。我收到编译器警告:“警告:赋值从指针生成整数而无需强制转换 @ msg[msglen+1] = "\0"”

char *msg = NULL;
int len = 10;
int msglen = 0;

while(<argument>) {

msg = (char *)calloc(len, 1);
strncpy(msg, <some string>, len);
msglen = strlen(msg);
msg[msglen+1] = "\0";

谢谢,我很感激你的帮助!

最佳答案

"\0"被视为一个常量字符串,当您尝试执行 msg[len - 1] = "\0" 时,该字符串的地址会被固定到位。因此您会收到消息“转换...”

改为这样做 msg[len - 1] = '\0'

关于c - ansi-c : assignment makes integer from pointer without cast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14447660/

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