Thursday, 2 August 2012

C function to decide if two strings are anagrams or not


Concept of Anagram--- two words are said to be anagrams, if one word can be obtained from the other by changing the order sequence of characters.
ex: abcde,adcbe, are anagrams

Solution: Sort the strings

 int anagram(String sourcestring, String targetstring) 
{
           return strcmp(sort(sourcestring),sort(targetstring));
 }

//sort method will sort the string based on their ASCII values and strcmp will compare those strings

//return value is 0 then the given words are Anagrams otherwise not.

No comments:

Post a Comment