views:

250

answers:

2

I get the following errors:

error: missing terminating " character

and

error: stray `\' in program

In this line of C code:

 system("sqlite3 -html /home/user/.rtcom-eventlogger/el.db \"SELECT service_id, event_type_id,free_text, remote_uid FROM Events WHERE remote_uid=\'%d\' ORDER BY start_time DESC;\" > lol.html", nr);

"nr" is a integer variable.

I have gone over this so many times but are totally stuck of finding a solution.

EDIT: The errors is the ouput while compiling with gcc if I didn't make that clear.

+2  A: 

Within a double-quoted string in C, I don't think that \' has any meaning. It looks like your backslashing there is meant to protect the single quotes in the shell, which means they should be double-backslashed within the string: remote_uid=\\'%d\\'.

JSBangs
I want the system call to print out remote_uid='contents-of-nr-variable' in the shell I still get an error with \\'%d\\'
bleakgadfly
At least in C99 both `\'` and `'` can be used in string literals.
Georg Fritzsche
This is gcc 4.1 on an ARM system.
bleakgadfly
@DreamCodeR, but does it compile with the `'` double-escaped? If so, then I suggest that you printf your statement so that you can see what's actually being expanded.
JSBangs
@JS Bang: printf("sqlite3 -html /home/user/.rtcom-eventlogger/el.db \"SELECT service_id, event_type_id,free_text, remote_uid FROM Events WHERE remote_uid='%d' ORDER BY start_time DESC;\" > lol.html", nr);Gives me the same error. Also the same error when I compile with remote_uid=\\'%d\\'
bleakgadfly
I can compile the line you posted just fine. Is there something on the surrounding lines that you're not showing us?
JSBangs
+1  A: 

Well, you don't need to escape the single quotes inside the string (e.g. \' should just be '), but I'm not sure that that would cause the error you're seeing.

Tyler McHenry