英文字典导入数据库

本文演示如何将英文字典数据导入到数据库中,详细介绍了运行示例的过程。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

int main(int argc, const char *argv[])
{
	//创建并打开数据库
	sqlite3 *db = NULL;
	if(sqlite3_open("./my.db",&db)!=SQLITE_OK)
	{
		fprintf(stderr,"sqlite3_open:%s\n",sqlite3_errmsg(db));
		fprintf(stderr,"sqlite3_open:%d\n",sqlite3_errcode(db));
		return -1;
	}

	//创建一张表格
	char* errmsg = NULL;
	char sql[128] = "create table if not exists dict(word char, mean char);"; 
	if(sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK)
	{
		fprintf(stderr,"sqlite3_exec:%s\n",errmsg);
		return -1;
	}

	//打开要导入的文件
	FILE* fd = fopen("./dict.txt","r");
	if(fd==NULL)
	{
		perror("fopen");
		return -1;
	}

	char buf[64] = "";
	char word[64] = "";
	char mean[64] = "";
	int i,j;
	while(1)
	{
		bzero(buf,sizeof(buf));
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值