#include "head.h"
int main()
{
//create
sqlite3 *pdb = NULL;
int ret = sqlite3_open("stu.db" , &pdb);
if(ret != SQLITE_OK)
{
printf("sqlite3_open fail : %s \n", sqlite3_errmsg(pdb));
return -1;
}
char *psql = "create table if not exists class6(word text ,means text );";
ret = sqlite3_exec(pdb,psql ,NULL,NULL,NULL);
if (ret!=SQLITE_OK )
{
printf("sqlite3_exec fail : %s \n", sqlite3_errmsg(pdb));
return -1;
}
FILE
char cmd[1024]={0};
char buff[1024]={0};
char *word;
char cat = ' ';
char *means;
int i=0;
FILE *pf = fopen("dict.txt","r");
while(1)
{
memset(buff , 0, sizeof(buff));
char *pret=fgets(buff, sizeof(buff), pf);
if(pret==NULL)
{
break;
}
word = strtok(buff, " ");
means = strtok(NULL, "\r\n");
memset(cmd ,0,sizeof(cmd));
sprintf(cmd , "insert into class6 values(\"%s\",\"%s\");" ,word , means);
if(sqlite3_exec (pdb ,cmd ,NULL,NULL, NULL) != SQLITE_OK )
{
printf("write fail : %s \n" , sqlite3_errmsg(pdb) );
return -1;
}
//select *from class6 where word like"air";
}
fclose(pf);
sqlite3_close(pdb);
return 0;
}
向数据库中录入字典
最新推荐文章于 2024-08-16 18:39:05 发布