C简单字典

01 //#include <conio.h>
02 #include <stdio.h>
03 #include <stdlib.h>
04 #include <string.h>
05  
06 struct dict
07 {
08    char word[24];
09    char mean[100];
10 } a[1000];
11  
12 void dict_list()
13 {
14      int i;FILE *fp;
15      fp=fopen("E:\\dict.txt","a+");
16      for(i=0;i<1000;i++) 
17      {
18          fread(&a[i],sizeof(struct dict),1,fp);
19          printf("   %s",a[i].word);
20          fclose(fp);
21          
22          
23      }
24 }
25 void find()
26 {    int i,j;FILE *fp; char*word=0;
27      fp=fopen(" E:\\dict.txt","a+");
28      printf("请输入单词");
29      scanf("%s",word);
30      for(i=0;i<1000;i++) 
31      fread(&a[i],sizeof(struct dict),1,fp);
32      if(a[i].word==word)
33      j=i;
34      printf("   %s %s",a[j].word,a[j].mean);
35      if(a[i].word!=word) printf("没有该单词 ");
36      fclose(fp);
37      
38 }   
39      
40 void append()
41 {  
42      FILE *fp;struct dict *p;
43      printf("请输入单词");
44      scanf("%s",a[0].word);
45      printf("请输入释义");
46      scanf("%s",a[0].mean);
47      fp=fopen(" E:\\dict.txt","a");
48      fwrite(&a[0],sizeof(struct dict),1,fp);
49      fclose(fp);printf("单词已新增");
50       
51 }   
52      
53 int main()
54 {  
55      int cmd=0;
56      for(;;)
57       {
58         printf("\n\************************\n\**   欢迎使用迷你字典!**\n\
59          ************************\n\
60         **   1 - 查询词条       **\n\
61         **   2 - 新增词条       **\n\
62         **   3 - 编辑词条       **\n\
63         **   4 - 删除词条       **\n\
64         **   5 - 退出字典       **\n\
65         ************************\n");
66         cmd = getchar() - '0';
67         switch(cmd)
68          {
69           case 0: dict_list(); break;
70           case 1: find(); break;
71           case 2: append(); break;
72  
73           default: return 0;
74          }
75   }
76   return 0;
77 }

转载于:https://my.oschina.net/u/928111/blog/98260

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值