日期:2014-05-17  浏览次数:20468 次

C语言链接mysql 语句中变量无法输入字符串
MYSQL my_connection;   
   
int res;   
int id;
char nam;
int num;
char sql[100];

mysql_init(&my_connection);    
   
if (mysql_real_connect(&my_connection, "localhost", "root", "111111","test",0,NULL,CLIENT_FOUND_ROWS))    
{   
printf("Connection success\n");   
    printf("insert id\n");
    scanf("%d",&id);
    printf("insert name\n");
    scanf("%s",&nam);
    printf("insert num\n");
    scanf("%d",&num);
    sprintf(sql,"insert into stu values('%d','%s','%d');",id,nam,num);

(节选部分程序)
编译后有错误:
insert.c:27:5: 警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat]

而且id在数据库中显示的与输入的值不相符。
求各路大神的帮助

mysql c

------解决方案--------------------
这个你还是去C语言专区问问看吧