c - 使用 Sqlite 中的记录集条目附加字符串时出错

标签 c string sqlite concatenation

我需要附加一个带有sqlite记录集列条目的字符串,我用这个

char a[16]=(unsigned char *)"Name: "+(unsigned char *)rs.recordset[0][1];

但我一直收到这个错误。

error: invalid operands to binary +

我做错了什么?

最佳答案

在 C 中,+ 符号不连接字符串。

根据 C11 标准,第 §6.5.6 章,加法运算符

For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to a complete object type and the other shall have integer type.[..]

因此,+ 不会连接两个字符串

您需要使用 strcat()连接两个字符串。

有点像

char a[16] = {0};
strcat(a, "name");
strcat(a, rs.recordset[0][1] );

只要 a 的长度足以正确保存最终输出(连接的字符串),就可以为您完成这项工作。

关于c - 使用 Sqlite 中的记录集条目附加字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35519581/

相关文章:

C:如果字符串内部存在子串,则将字符串中的小写字母改为大写字母

c - C中结构内部的结构

python - 在python中按其子字符串数值对字符串进行排序

c++ - realloc() 问题,未分配

c - 在 32 位 Controller 上访问 SFR(特殊功能寄存器)

c++ - 字符串中的名称 C++

c - findAndReplace函数的实现

SQlite:unix 时间戳的列格式;整数类型

r - 如何在 R 包中包含 sqlite 数据库文件。以便我可以与数据库文件一起共享/发布它?

ruby-on-rails - Ruby on Rails 迁移非常慢