找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3439|回复: 1
打印 上一主题 下一主题
收起左侧

c语言电子词典源程序

[复制链接]
跳转到指定楼层
楼主
ID:60266 发表于 2014-8-18 21:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include<stdio.h>

#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define LEN sizeof (struct cte)   /*宏定义*/
/*..........................
............................
............................*/
struct cte                        /*结构体定义*/
{
char  chinese[100] ;
char  English[100] ;
struct cte *next;
};/*........................
............................
............................
*/
struct cte *insert(struct cte *head)  /*单词添加*/
{
struct cte *p1,*p2,*p3;
unsigned int a , b;
p1=p2=head;
if (head == 0)
{
p1 = (struct cte *)malloc(LEN);
printf("1.中译英\n");
printf("2.英译中\n");
scanf("%d",&a);
if (a==1)
{
printf("请输入中文:\n");
scanf("%s",&p1->chinese);
printf("please input english:\n");
scanf("%s",&p1->English);
}
else if (a==2)
{
printf("please input english:\n");
scanf("%s",&p1->English);
printf("请输入中文:\n");
scanf("%s",&p1->chinese);
}
else
{
printf ("输入有误\n");
}
head = p1;
head->next=0;
}
else
{
p1=(struct cte *)malloc(LEN);
p3=head->next;
head->next=p1;
p1->next=p3;
printf("1.中译英\n");
printf("2.英译中\n");
scanf("%d",&b);
if (b==1)
{
printf("请输入中文:\n");
scanf("%s",&p1->chinese);
printf("please input english:\n");
scanf("%s",&p1->English);
}
else if (b==2)
{
printf("please input english:\n");
scanf("%s",&p1->English);
printf("请输入中文:\n");
scanf("%s",&p1->chinese);
}
else
{
printf("输入有误\n");
}
}
return head;
}
/*...........................
.............................
.............................*/
void cscan(struct cte *head)   /*汉译英*/
{
struct cte *p;
char a[100];
printf("请输入:");
scanf("%s",a);
p = head;
if(head==0)
printf("本词典当前为空\n");
while(p!=0)
{
if (strcmp(a,p->chinese)==0)
{
         printf("English:%s",p->English);
  p=0;
}
else if (strcmp(a,p->chinese) != 0)
p=p->next;
if(p==0)
printf("没这词语");
}
system("pause");
}
/*............................
..............................
..............................*/
void escan(struct cte *head)   /*英译汉*/
{
struct cte *p;
char a[100];
printf("please input a word:");
scanf("%s",a);
p=head;
if(head==0)
printf("本词典当前为空\n");
while(p!=0)
{
if (strcmp(a,p->English) == 0)
{
printf("中文:%s",p->chinese);
p = p->next;
}
else if (strcmp(a,p->English)!=0)
p = p->next;
if(p==0)
printf("没这词语");
}
system("pause");
}
/*.............................
...............................
...............................*/
void print (struct cte *head)  /*词典查看*/
{
struct cte *p;
p = head;
if(p==0)
printf("该词典没有任何记录\n");
while  (p !=0)
{
printf("中文:%s English:%s\n",p->chinese,p->English);
p = p->next;
}
system("pause");
}
/*..............................
................................
................................*/
void main()
{  
void cscan(struct cte *head);
void escan(struct cte *head);
struct cte  *insert(struct cte *head);
struct cte *start(void);
struct cte *B=0;
int a,b=0,c;
/*struct cte n;*/
while(1)
{   
        printf("\n\n\n\n\t\t\t\t");
        printf("************\n\t\t\t\t");
        printf("1.汉译英\n\t\t\t\t");
    printf("2.英译汉\n\t\t\t\t");
    printf("3.添加新词\n\t\t\t\t");
    printf("4.查看词典\n\t\t\t\t");
        printf("5.清除屏幕\n\t\t\t\t");
        printf("************\n\n");
        printf("请选择\n");

        scanf("%d",&a);
if(a==1)
{
cscan(B);
system("cls");
}
else if(a==2)
{
escan(B);
system("cls");
}
else if(a==3)
{
B = insert(B);
system("cls");
}
else if(a==4)
{
print(B);
system("cls");
}
else if(a==5)
system("cls");
else
printf("输入有误:");
}
}

                                                                                            

                                                                               
                                                                                                                                                       
                                                       

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:175839 发表于 2017-12-20 02:22 | 只看该作者
这个程序在Visual C++6.0中运行不了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表