Mysql c api row [0] to row

When using the MYSQL C API to query the results. The results are returnd as type MYSQL_ROW, which, according to the MYSQL C API documentation, I can easily print f ("% s", row [0]). But what if I want to pass the content of string [0] to a string or char *?

+1


source to share


2 answers


The% s format should only accept char *, so from your description it looks like MYSQL_ROW is indeed char **, and string [0] will give char * anyway.



I don't see how using sprintf () (or the safer but non-standard asprintf ()) will do any good, but you can think about it if you feel better.

+1


source


You can use sprintf () , but you still need to know the length of the string contained in line [0] so that you can allocate enough memory.



Caveat: BCS correctly specifies that your data will be truncated if line [0] contains additional nul bytes. If you know how much data is stored in line [0], using memcpy () is probably the best solution.

0


source







All Articles