I've been working on a program which writes to MySQL. It needs some variables posting into the database and I'm having trouble elegantly constructing a char * string to send to the MySQL connector.
Here's what I'm doing at present, apologies for my awful code, it works but seems unnecessarily long-winded and ugly. Does anyone know of a more elegant way to insert variables into a char * string? If there were a need for lots of SQL queries this method could get ugly very quickly!
Thanks for any pointers (heehee)
char *arg1a = "select * from database where field1 = '";
char *arg1b = "' and field2 = '";
char *arg1c = "'";
sqlarg = (char *)malloc((strlen(variable1) + strlen(variable2) + strlen(arg1a) + strlen(arg1b) + strlen(arg1c) + 1)
/* completed query now stored in sqlarg */