在 64 位 linux 系统上的以下程序中,我无法将 row[1] 转换为 unsigned long:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <mysql.h>
MYSQL *conn;
int main()
{
char query[6500];
int mysqlStatus = 0;
MYSQL_RES *result;
MYSQL_ROW row;
int num_rows_result = 0;
unsigned long long_ip;
int i = 0;
/* connect to db and initialize arrays with values read from db */
conn = mysql_init(NULL);
mysql_real_connect(conn, "host", "username", "passwd", "db", 0, NULL, 0);
sprintf(query," ");
sprintf(query,"SELECT * FROM rolla_sorted_in1");
mysqlStatus = mysql_query(conn, query);
if (mysqlStatus)
{
printf("there was a problem with the following mysql query:\n");
printf("\t%s\n",query);
}
result = mysql_store_result(conn);
num_rows_result = mysql_num_rows(result);
if ( num_rows_result > 0 )
{
for (i=0;i<10;i++)
{
row = mysql_fetch_row(result);
long_ip = (unsigned long) row[1];
printf("row[1]: %s, long_ip: %lu\n",row[1],long_ip);
}
}
else
{
printf("sorted_in1 is empty\n");
}
mysql_free_result(result);
printf("sizeof(ptr): %lu, sizeof(ul): %lu\n",sizeof(row[1]),sizeof(long_ip));
}
这是输出:
row[1]: 419670989, long_ip: 6420226
row[1]: 1102313293, long_ip: 6420354
row[1]: 3294303560, long_ip: 6420482
row[1]: 1408935374, long_ip: 6420610
row[1]: 3242924999, long_ip: 6420738
row[1]: 1509939008, long_ip: 6420866
row[1]: 2707912135, long_ip: 6420994
row[1]: 2556917191, long_ip: 6421122
row[1]: 3510964689, long_ip: 6421250
row[1]: 1186041166, long_ip: 6421379
sizeof(ptr): 8, sizeof(ul): 8
任何指针?谢谢。