Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE IN C PROGRAMMING Please include lots of comments to help me with understanding 1. (100 points) Write a program that prompts the user to

WRITE IN C PROGRAMMING

Please include lots of comments to help me with understanding

1. (100 points) Write a 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.txtOutput: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 withan 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 100characters.Assume the input file contains no more than 1000 words.

2.The followingfunctionis providedin anagram.c:int are_anagram(char *word1, char *word2);word1 andword2arestringscontaining the words to be checked for anagram. The function returns1 if the two words are anagramof 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

...

Here is the are_anagram() function:

int are_anagram(char *word1, char *word2)

{

int letter_counts[26]={0};

char *p; char *q;

int i, count =0;

char ch;

for(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;

}

Here is the contents of the text file (words.txt):

rail safety inch roast beef eat for BSE William Shakespeare Madam Curie lake morning Radium came I am a weakish speller Heir hire computer science chin knee array length leak kiss

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions