Hello everyone!
I have seen some code where some variable gets inserted into string throught the % sign, like so -

("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, ... ", someInt, someChar, someChar... )

I have tried to look it up in google but I do not know what this is called. What is it and where can I find a reference for it? Thanks!

Recommended Answers

All 5 Replies

("insert into songs values (%Q ,%d, %d, %Q, %Q, %Q, ... ", someInt, someChar, someChar... )

Do you use someting like sprintf_s()? (or sprintf())
example:

char c = 'x';
int i = 123;
char buffer[1024];
sprintf(buffer, "Test number: %d, test char, %c", i,c);

No, but I want to use this for sqlite3 to insert data into tables, like combine the "insert into" command with data. Do I have to "print" it to string and then use it? Thanks

The string with the %x symbols in it are parsed to find each symbol. The letter is then looked at to figure out what field is supposed to go there. Then the string is changed by removing the %x and whatever field is requested replaces it.

Usually the data comes out of variables and/or structures the program has already read or generated.

There is no function to do this if that's what you're looking for. The function is written by the programmers developing the system.

its not the boost library, I had a look again - it is the sprintf function. Now I will look at the documentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.