標題: c語言電子詞典源程序 [打印本頁]

作者: heise    時間: 2014-8-18 21:50
標題: c語言電子詞典源程序
#include<stdio.h>

#include<string.h>
#include<malloc.h>
#include<stdlib.h>
#define LEN sizeof (struct cte)   /*宏定義*/
/*..........................
............................
............................*/
struct cte                        /*結(jié)構(gòu)體定義*/
{
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.英譯中\(zhòng)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.英譯中\(zhòng)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("本詞典當(dāng)前為空\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("本詞典當(dāng)前為空\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("輸入有誤:");
}
}

                                                                                            

                                                                               
                                                                                                                                                       
                                                       


作者: 1343283034    時間: 2017-12-20 02:22
這個程序在Visual C++6.0中運行不了




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1