单词导入
#include <head.h>
int main(int argc,const char * argv[])
{
sqlite3* db;
if((sqlite3_open("./dict.db",&db)) != 0)
{
printf("sqlite3_open error %d\n",sqlite3_errcode(db));
return -1;
}
printf("sqlites_open success\n");
int a;
char str1[128] ="create table if not exists dict (world char,translate char);";
char *errmsg;
if((sqlite3_exec(db,str1,NULL,NULL,&errmsg)) != 0)
{
printf(" __%d__sqlites:%s\n",__LINE__,errmsg);
}
printf("open success\n");
FILE* fd;
fd = fopen("./dict.txt","r+");
if(fd < 0)
{
printf("fopen error __%d__\n",__LINE__);
}
printf("fopen success\n");
char buf[128] = "";
char str[128] = "";
int i = 0;
while(1)
{
memset(str,0,sizeof(str));
if((fgets(str,sizeof(str),fd)) ==NULL)
{
break;
}
for( i = 0; i < strlen(str);i++)
{
if(str[i] ==' '&&str[i+1] ==' '&&(str[i-1] >= 'a'||str[i-1] <= 'z'))
{
str[i+1]='\0';
sprintf(str1,"insert into dict values (\"%s\",\"%s\");",str,str+i+3);
if((sqlite3_exec(db,str1,NULL,NULL,&errmsg)) != 0)
{
printf(" __%d__sqlites:%s\n",__LINE__,errmsg);
}
break;
}
}
}
if((sqlite3_close(db)) !=0)
{
printf("close error %d\n",sqlite3_errcode(db));
return -1;
}
printf("sqlites_close success\n");
return 0;
}