How to remove a character from output string by *printf() function family using formats? it’s possible?
from macros this macros:
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
);
I get output something like this:
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,
);
A puts(s) call prints the following:
insert into foo(name,serie,red,blue,yellow,purple,) values('Ari tol',-1,-1,-1,-1,0)
But I have a problem, the , before first ) that turns the SQL query invalid. I’m looking for some way to remove it from string. Maybe by some format that can be used in printf() functions family or re-define the macros. I don’t know. It’s just a try to don’t write routines that search for index first of ) and after another call to a string-replace function by index.
You can’t remove things at the preprocessor level. In this case, though, you can define X to put the comma before each item, and remove the comma after “serie” and “‘%s'”.