如何使用格式通过* printf()函数系列从输出字符串中删除字符?这是可能的?
来自宏这个宏:
char *s =
g_strdup_printf(
"insert into foo(name,serie,"
#define X(a, b) #a ","
LIST ") "
#undef X
#define X(a, b) "%d,"
"values('%s'," LIST "%d" ")",
#undef X
#define X(a, b) bol->a,
boletim->aname, serie, LIST
#undef X
);
我输出的内容如下:
char *s =
g_strdup_printf(
"insert into foo(name,serie,"
"red" "," "blue" "," "yellow" "," "purple" "," ") "
"values('%s'," "%d," "%d," "%d," "%d," "%d" ")",
boletim->aname, serie, boletim->red, boletim->blue, boletim->yellow, boletim->purple,
);
puts(s)
来电显示以下内容:
insert into foo(name,serie,red,blue,yellow,purple,) values('Ari tol',-1,-1,-1,-1,0)
但是我遇到了问题,,
在第一个)
之前导致SQL查询失效。我正在寻找一些方法将其从字符串中删除。也许通过某种格式可以在printf()
函数族中使用或重新定义宏。我不知道。这只是尝试不编写首先搜索)
索引的例程,然后再按索引调用字符串替换函数。
答案 0 :(得分:1)
您无法在预处理器级别删除内容。但是,在这种情况下,您可以定义X以在每个项目之前放置逗号 ,并在“serie”和“'%s'”之后删除逗号。