如何使用格式通过 *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()
函数族中使用的格式或重新定义宏。我不知道。这只是一个尝试,不要编写)
在通过索引调用字符串替换函数之前和之后搜索索引的例程。