Question: DO NOT USE MALLOC | DO NOT USE MALLOC C LANGUAGE - Write a main function to find the anagram (I/O) based on are_anagram and
DO NOT USE MALLOC | DO NOT USE MALLOC C LANGUAGE - Write a main function to find the anagram (I/O) based on are_anagram and file words.txt. The user will enter the name of the file, for example: Enter the text file name: Words.txt. If they enter a name which is incorrect, then output error. The program will restrict contents from words.txt file then find the anagram. Based on the given words.txt above, the output should be: (print out) 1. Inch Chin 2. Roast beef Eat for BSE so on And also output these anagrams into a file named: words.txt.ang (same name as the input file with an extension .ang). Then out a messages: Anagrams are written to file: words.txt.ang Assume the filename is no more than 100 characters. Length of each line in the input file no more than 100 char. The input file contains no more than 1000 words. Use array 2-dimensional. Loops. Newbies level . DO NOT USE MALLOC, use pointers because I have not studied it yet! As simple as possible and please leave some comments. Love you! DO NOT USE MALLOC | DO NOT USE MALLOC ******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; } *****Content of words.txt file: 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 ****this is the read_line function if you need*** int read_line(char *str, int n) { int ch, i =0; while ((ch = getchar()) != ' ') { if (i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
