Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago