把dict.txt文件,导入数据库中。需要把单引号先转成 点 再插入。
不能插入带有单引号的字符串 如 one's 转换成 one.s 再插入。否则导入不成功。
1,导入源码:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sqlite3.h>
#define DATABASE "my.db"
int main(int argc, char const *argv[])
{
//把文件导入数据库中
sqlite3 *db;
FILE *fp;
if(SQLITE_OK !=sqlite3_open(DATABASE,&db)){
perror("sqlite err");
exit(1);
}
fp = fopen("dict.txt","r");
if(fp==NULL){
perror("err");
exit(1);
}
char str[300]={0};
char word[30]={0};
char introduct[100]={0};
char *errmsg;
char sql[200]={0};
sprintf(sql,"create table dict (word text,translation text)");
if(SQLITE_OK !=sqlite3_exec(db,sql,NULL,NULL,&errmsg)){