web123456

How to implement a simple dictionary using C language

Question Requirements:

Implement a simple English-Chinese dictionary, and the vocabulary has 10 words.
Implement functions:
When entering a word, you can output the corresponding Chinese
When entering Chinese, you can output the corresponding English
If the entered word or Chinese search does not exist, the output "The content you are looking for does not exist, please re-enter".
[Requires to use a linked list to implement it, and the program does not exit until the word that can be found. As long as it cannot be found, it must be repeated.]

Provide 10 words
one
Two
three
four
five
six
seven
eight
nine
ten

#include <>
 #include <>
 #include <>

 #define WORDSIZE 20
 #define MEANSIZE 25


 struct Record{
	 char word[WORDSIZE];
	 char means[MEANSIZE];
 };

 struct Node{
	 struct Record data;
	 struct Node *next;
 };

 int flag = 0;

 void initData(struct Node *head);
 void printData(struct Node *head);
 void searchByWord(struct Node *head,char *word);
 void searchByMean(struct Node *head,char *mean);
 int main()
 {
	 struct Node* head;
	 head = (struct Node*) malloc(sizeof(struct Node));
	 initData(head);
	 int choose;
	 char input[20];
	 while(!flag){
		
		 printf("------------------\n");
		 printf("1. Check English according to Chinese\n");
		 printf("2. Look up Chinese according to English\n");
		 printf("------------------\n");
		 printf("Please enter your selection\n");
		 scanf("%d",&choose);
		 switch(choose)
		 {
			 case 1:
				 printf("Please enter (Chinese):");
				 scanf("%s",input);
				 searchByMean(head,input);
				 break;
			 case 2:
				 printf("Please enter (English):");
				 scanf("%s",input);
				 searchByWord(head,input);
				 break;
			 default:
				 printf("Input is incorrect, please re-enter\n");
				 break;
		 }
		 //printData(head);
		
	 }
	 return 0;
 }

 //Initialize the data
 void initData(struct Node *head)
 {
	 char english[10][6] = {"One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
	 char chinese[10][10] = {"one","two","three","four","five","six","seven","eight","nine","ten"};
	 struct Node *p = head;
	 int i;
	 for(i=0;i<10;i++)
	 {
		 struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
		 strcpy((temp->data).word,english[i]);
		 strcpy((temp->data).mean,chinese[i]);
		 //printf("%s",(temp->data).word);
		 //printf("%s",(temp->data).mean);
		 p->next = temp;
		 p = p->next;
	 }
	 p->next = NULL;
 }

 //Print out the linked list data
 void printData(struct Node* head)
 {
	 struct Node* p = head;
	 p = p->next;
	 while(p!=NULL){
		 printf("word is; %s\n",(p->data).word);
		 printf("mean is:%s\n",(p->data).mean);
		 p = p->next;
	 }
  }
 
  //Check Chinese according to English
  void searchByWord(struct Node *head,char *word)
  {
 	 struct Node* p = head;
 	 p = p->next;
 	 while(p!=NULL){
 		 if(strcmp((p->data).word,word)==0)
 		 {
 			 printf("\t-- Found ---\n");
 			 printf("\tENGLISH\tCHINESE\n");
 			 printf("\t%s\t%s\n",(p->data).word,(p->data).mean);
 			 printf("\t-------------------------------------------------------------------------------------------------------------------------
 			 flag = 1;
 			 break;
		  } else{
		 	 p = p->next;
		  }
		 
	  }
	  printf("Not found, please re-enter\n");
   }
  
   //Check English according to Chinese
   void searchByMean(struct Node *head,char *mean)
   {
  	 struct Node* p = head;
 	 p = p->next;
 	 while(p!=NULL){
 		 if(strcmp((p->data).mean,mean)==0)
 		 {
 			 printf("\t-- Found ---\n");
 			 printf("\tENGLISH\tCHINESE\n");
 			 printf("\t%s\t%s\n",(p->data).word,(p->data).mean);
 			 printf("\t-------------------------------------------------------------------------------------------------------------------------
 			 flag = 1;
 			 break;
		  } else{
		 	 p = p->next;
		  }
		 
	  }
	  printf("Not found, please re-enter\n");
  	
    }

Recently, I wrote a small demo for my junior brother, and I asked myself to review the knowledge of C language. . .