#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include "set.h"
int main()
{
        FILE *fp;
        int i;
        char string[1024];
        char host[1024];
        char user[1024];
        char passwd[1024];
        char db[1024];
        fp=fopen("conf.txt","r");
        fread(string,11,4,fp);
        char *p;
        p=string;
        p=set(p,host);
        p=set(p,user);
        p=set(p,passwd);
        set(p,db);
 ///////////////上面部分是从配置文件读入host,user,passwd,db的值///////////////////       
  /////////////这下面的部分就是把in.txt内的内容逐行的插入到数据库"tmp"的"xiong"表中mac_address字段/////////////////////////////////     
        MYSQL *mysql;
        printf("1\n");
        mysql_init(mysql);
        printf("2\n");
        if((mysql=mysql_real_connect(mysql,host,user,passwd,db,0,NULL,0))==NULL)
        {
                printf("error connecting to database:%s\n",mysql_error(mysql));

        }
        else printf("connected...\n");
        char ch;
        fp=fopen("in.txt","r");
        ch=fgetc(fp);
        char *query;
        int top,t;
        top=0;
        while(ch!=EOF)
        {
                if(ch=='\n')
                {
                     query[top]='\n';
                        char *sql;
                        sprintf(sql,"insert into xiong (mac_address) values ('%s')",query);
                        t=mysql_real_query(mysql,sql,(unsigned int)strlen(sql));
                        if(t)
                        {
                                printf("error making query:%s\n",mysql_error(mysql));
                        }
                        else printf("query made...\n");
                        top=0;
                }
                else
                  query[top++]=ch;
               ch=fgetc(fp);
        }
        mysql_close(mysql);
        return 0;
}
程序运行到mysql_init()就core dump 了
哪位高手能指点指点吗?
我的QQ号:422987597
我的MSN:xubearxx@hotmail.com