Question

SENG 265 A01/AD2 Page 14 Qeestion 24 (45 marks) Write a C function to detennine lÉ one string is an anagras of snothen, Yowr function is emagsm 0 will ake two strings as parsmetens, and will eturens 1 if the string wre anagrams of each other, otherwise it will retuns An anagram is a pbrase that uses all the letters-and exactly those letters-of some other phrase Below are some anagram examples: Zastre: Brat Stephen Harper: R? Rent, perhaps? Dormitory: Dirty Room . . The check is in the maidls Claim Heck,I smt it (heh) I sat there with Sally Aha! Lithely twsters Notice the namber of spaces and use of punchuation in an anagram can differ greatly from the original phrase. We ignore spaces and panctustion rehen checking if two phrass are anegrams of each other As a guide towards a solution, assume you can use an already weitten function named aipha to index which takes a single parameter (a character).It returna if the character is not an alphabetical character, otherwise it returns a vaise from 1 to 26 if the character is a letter from the English alphabet. (When the fonction is passed Aor s as the argument, it returea 1, when B. or ?s passed, it returns 2i etc.) The noxt page (page IS) is avalable for yeur wok/ ansver lf seeded Sone marks will be given foe the quality of your ansswer

Write the is_anagram function with details in pic.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <string.h>

int is_anagram(char arr1[], char arr2[]){
   int count[26] = {0};
   int i;
   arr1 = strlwr(arr1);
   arr2 = strlwr(arr2);
   for(i = 0;i<arr1[i]!='\0';i++){
       if(arr1[i]>='a' && arr1[i]<='z')
           count[arr1[i]-'a']++;
   }
   for(i = 0;i<arr2[i]!='\0';i++){
       if(arr2[i]>='a' && arr2[i]<='z')
           count[arr2[i]-'a']--;
   }
   for(i = 0;i<26;i++){
       if(count[i]!=0){
           return 0;
       }
   }
   return 1;  
}

int main(int argc, char *argv[]) {
   char input1[100];
   char input2[100];
   printf("Enter input1: ");
   scanf("%s",&input1);
   printf("Enter input2: ");
   scanf("%s",&input2);
   printf("%d\n",is_anagram(input1,input2));
   return 0;
}

Enter input1: god Enter input2Dog Process exited after 7.949 seconds with returnvalue 0 Press any key to continue - -

\color{red}Please\; upvote\;the \;solution \;if \;it \;helped.\;Thanks!

Add a comment
Know the answer?
Add Answer to:
Write the is_anagram function with details in pic. SENG 265 A01/AD2 Page 14 Qeestion 24 (45...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT