Code:#include<stdlib.h> #include<stdio.h> #include<string.h> struct word_l { char word[100]; char meaning[100]; struct word_l * next; }; typedef struct word_l word; void addNode(word *); void displayNode(word *); char choose(void); int main() { char choice; word *head; head = (word *)malloc(sizeof(word)); head->next=NULL; choice=choose(); switch(choice) { case 'a': addNode(head); break; case 'e': exit(0); } displayNode(head); exit(0); } void addNode(word *head) { printf("Enter word and Meaning and at End enter NO\n"); printf("Word :-"); gets(head->word); printf("Meaning:-") ; gets(head->meaning); fflush(stdin); if(strcmp(head->word,"NO")==0) head->next=NULL; else { head->next=(word *)malloc(sizeof(word)); addNode(head->next); } return; } void displayNode(word *head) { printf("\v-----------------------------------------------\n"); while(head->next->next) { printf("%10s:- %s\n", head->word,head->meaning); head = head->next ; } printf("\v-----------------------------------------------\n"); } char choose(void) { char choice; printf("a)Recursion\ne)exit\nChoice:-"); choice=getchar(); return choice; }
output is
a)Recursion
e)exit
Choice:-a
Enter word and Meaning and at End enter NO
Word :-Meaning:-
Enter word and Meaning and at End enter NO
Word :-apple
Meaning:-apple
Expected output is
a)Recursion
e)exit
Choice:-a
Enter word and Meaning and at End enter NO
Word :-
Meaning:-
Enter word and Meaning and at End enter NO
Word :-apple
Meaning:-apple