//导入数据到表格
246 int insert_table(FILE *fd)
247 {
248 int rec = 0;
249 char word[128] = "";
250 char mean[128] = "";
251 char sql[128] = "";
252 char flag = 0;
253 //int i = 0;
254 char *errmsg;
255 while (1)
256 {
257 bzero(word,sizeof(word));
258 bzero(sql,sizeof(sql));
259 if (rec = fscanf(fd,"%s %s%c",word,mean,&flag)>0)
260 {
261 sprintf(sql,"insert into dictionary values(\"%s\",\"%s",
262 word,mean);
263 while(1)
264 {
265 if (flag == ' ')
266 {
267 bzero(mean,sizeof(mean));
268 rec = fscanf(fd," %s%c",mean,&flag);
269 sql[strlen(sql)] = 32;
270 if (rec>0)
271 {
272 strcat(sql,mean);
273 }
274 }
275 else
276 break;
277 }
278 strcat(sql,"\");");
279
280 if (sqlite3_exec(db,sql,NULL,NULL,&errmsg)!=SQLITE_OK)
281 {
282 fprintf(stderr,"[ %c ] : %s",sqlite3_errcode(db),sqlite3_errmsg(db));
283 return -1;
284 }
285 }
286 else
287 {
288 break;
289 }
290 }
291 return 0;
292 }
网络编程 --- Day05
最新推荐文章于 2024-11-10 07:36:16 发布