I have the following code in C that makes a connection to a mysql database and performs a query:
#include <mysql.h>
#include <stdio.h>
int main(void){
MYSQL Connection;
MYSQL_RES *res;
MYSQL_ROW row;
mysql_init(&Connection);
if(mysql_real_connect(&Connection, "127.0.0.1", "root", "xururuca", "test", 0, NULL, 0)){
printf("Connection: Ok...\n\n");
}else{
printf("Error in connection\n\n");
}
mysql_query(&Connection ,"select id from accounts where username='Alan' and password='lixodoesgotogostoso';");
res=mysql_store_result(&Connection);
row=mysql_fetch_row(res);
printf("%s\n", row[0]); //ele imprime 3 (Ok...)
int userID=row[0]; //Agora tento passar esse 3 para uma variável do tipo int...mais não rola
printf("%d\n", userID); //Imprime lixo e não 3 que seria o correto
mysql_free_result(res);
mysql_close(&Connection);
return 0;
}
When compiling: warning: initialization makes integer from pointer without cast [-Wint-conversion] |
So, I want my 'result set' to go to the variable userID, but how do I do it without major problems?