Looking to write a program to compute the number of common words between two str
ID: 3656876 • Letter: L
Question
Looking to write a program to compute the number of common words between two strings. The idea is for the program to read the first line of input (i.e. the first string) and store its distinct words in a linked list, where each distinct word is stored in one node of this linked list as a string variable. Each word is expected to have at most 30 characters; when one word is too long, terminate the program (means each word can be stored in a character array of length 31). The end result requires a main file (containing the main function), a word.c and word.h file for operations over the linked list that stores words of the first string in its nodes. The helper function that reads one word from the input can be included here. Finally, also need same.c and same.h, the code for functions that reads words from the second line and makes use of operations from word.c to compute the number of common words.Explanation / Answer
#include #include #include void main() { char a[80],b[80]; int i,j,t; clrscr(); printf("Enter 1st string "); gets(a); fflush(stdin); printf("Enter 2nd string "); gets(b); printf("Common characters are : "); for(i=0;a[i]!='';i++) { for(j=i-1;j>=0;j--) if(a[i]==a[j]) break; if(j==-1) for(t=0;b[t]!='';t++) if(a[i]==b[t]) { printf("%c",a[i]); break; } } getch(); }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.