Question: Write a C coding language program that prompts the user to enter the name of a file. The program finds the anagrams in the file.

Write a C coding language program that prompts the user to enter the name of a file. The program finds the anagrams in the file.

Enter the file name: words.txt

Output: anagrams are written to file: words.txt.ang

The program reads the content of the file and stores the words in an array of strings, the program then finds the anagrams and writes the anagrams to the output file.

1. Name your program fileIO.c. The output file name should be the same name as the input file but with an added extension of .ang. In this example, the original file name is words.txt. The output file name is then words.txt.ang. Assume the file name is no more than 100 characters. Assume the length of each line in the input file is no more than 100 characters. Assume the input file contains no more than 1000 words.

2. The following function is provided in anagram.c: int are_anagram(char *word1, char *word2); word1 and word2 are strings containing the words to be checked for anagram. The function returns 1 if the two words are anagram of each other and return 0 otherwise.

3. The output file should be in the following format. The output file contains all the anagrams.

1 inch chin

2 roast beef eat for BSE

int are_anagram(char *word1, char *word2)

{

int letter_counts[26]={0};

char *p; char *q;

int i, count =0;

char ch;

forr(p = word1; *p!='\0'; p++)

if(isalpha(*p))

{

ch = tolower(*p);

letter_counts[ch - 'a']++;

}

for(q = word2; *q!='\0'; q++)

if(isalpha(*q))

{

ch = tolower(*q);

letter_counts[ch - 'a']--;

}

for(i =0;i<26;i++)

{

if(letter_counts[i]==0)

count++;

}

if(count == 26)

return 1;

else

return 0;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!