After hours of unsuccessfully trying to fetch a row from my MySQL DB and saving the output to a string array, I finally decided to come here and ask for help, because I apparently can't solve it myself. This is no homework, I am merely trying to write a simple command line mysql-client that can be integrated into other C projects. As I am not extracting integers from the DB, I can't work with atoi :(
My problem is that I am not able to use sprintf() in order to write the value of row[0] into a field_array[i], because unlike I thought, row[] is not being incremented on every call to mysql_fetch row(). Actually, when calling this command, row[0] only gets updated with the content of the MYSQL_RES *struct.current_row, in this case MYSQL_RES *headers.current_row. Thus the problem is that I want to be able to call mysql_fetch_row() normally, whilst incrementing the int i for the field_array[i] to be able to successfully sprintf() all values.
Below, the relevant code. If anything is missing, please tell me :)
Used variables:
MYSQL_ROW row;
MYSQL_RES *headers;
char field_array[50][100];
Part of the code which I don't get to work as intended:
while ((row = mysql_fetch_row(headers)))
{
for(int i = 0; i < num_fields; i++)
{
printf("%s\n", row[i] ? row[i] : "NULL");
sprintf(&field_array[i], "%s", row[i]);
}
}
Please help me, if possible. I am using the Connector/C MySQL API, working on a windows 7 x64 environment with mingw32/GCC (Code::Blocks).
My intention is to write all values into field_array to work with them later on.