How to store the string in %s

Hello all,

I am studying source code of MySQL.I noted that in error messages they are using %s,%d here %s is used to store the database name,table name which is chose by user,and %d for error number. I want to know how they store the string in %s.can you help me for that.

Answer Answered by Jan Steinman in this comment.

I do not know of your specific case, but this looks like a format argument to the C printf(3) function.

If you are on UNIX or Linux, I suggest you type "man 3 printf" at a command prompt. that will show (in part): "The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is introduced by the % character."

If it is indeed a printf(3) format string, "%s" would mean that a corresponding argument to printf(3) is to be interpreted as a character array, and the "%d" would mean that the corresponding argument is interpreted as a decimal number.

So the function call might look something like this: "printf('%s, %d', databasename, #ENOENT)". There is a list of common error codes in /usr/include/sys/errno.h .


Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.