c - 传递 ‘strcat’ 的参数 2 使指针来自整数而不进行强制转换 [-Wint-conversion]

标签 c fifo strcat

我正在读取一个 fifo,然后尝试用它创建另一个不同格式的数组。 我知道 buf 按预期获取其值,因为将其打印出来很好。

char graphic[100];
char buf[100];
read(fd_read,&buf,50);
for(int i=0; i<10; i++){
strcat(graphic, buf[i]); }

给我错误:

passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]

我在 Linux 上使用 eclipse,在 C 上。 ...帮助?

最佳答案

strcat 的签名是:

char *strcat(char *dest, const char *src);

即第二个参数应该是指向 char 的指针以 '\0' 结尾的数组。在您的情况下,您正在传递一个 char角色。

而不是 for(int i=0; i<10; i++){ strcat(graphic, buf[i]); } ,您可能只需要:(假设 graphic 在某处初始化)

strcat(graphic, buf); /* Use strncat for limited number of characters */

还要确保 string.h包含在您的程序中。

<小时/>

要自己附加字符,您可以仅使用赋值而不是使用函数。

/* Append one character (ith character of buf[i] ) */
const size_t len = strlen(graphic);
if(len + 1 >= sizeof graphics) { /* Error handling */ }
else {
  graphic[len] = buf[i];
  graphic[len + 1] = '\0';
}

关于c - 传递 ‘strcat’ 的参数 2 使指针来自整数而不进行强制转换 [-Wint-conversion],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36741825/

相关文章:

linux - Reading FIFO 第一次不显示

比较字符串之间有多个空格

在 C 编程中将两个字符串合二为一

c - 从管道读取时返回不正确的数据

c - 减去 : missing filename using execvp()

C : enQueue : How does create a new pointer to the tail?

c - 程序集编译错误(gcc4.2.4=win, gcc4.3.3=fail)

读取时的linux FIFO block

在 UNIX 中创建 FIFO

c - 在读取内存时递增变量