gpt4 book ai didi

c - 将 char 存储在 char [] 中可以从指针生成整数而无需强制转换?

转载 作者:太空宇宙 更新时间:2023-11-04 02:53:28 24 4
gpt4 key购买 nike

<分区>

所以我正在为一个最终将成为消息或 IRC 服务器的更大程序的框架编写代码。

我遇到的问题是当试图通过将“\n”的值更改为“\0”来从输入到字符缓冲区的输入中删除行尾字符时

存储缓冲区的结构如下所示:

typedef struct{
pthread_t tid; //the id of the thread
char input[8192]; //message space of 2 to the 13th power
}thread_in;

thread_in user[3];

然后我创建了一个指向我的结构的临时数组指针,以便于调用它。

char user_input[8192];
strncpy(user[num].input, user_input, 8192);

问题出在给我以下警告的下一行代码:

Warning: assignment makes integer from pointer without a cast

这是代码:

user_input[strlen(user[num].input)-1] ="\0";

有人能指出为什么它认为赋值给一个整数,因为它是一个字符数组。

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