Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

C programing: function to check for an anagram.

OpenStudy (anonymous):

keep one pointer at the beginning of the string and one pointer at the end. make sure they have the same value. increment the start pointer and decrement the end pointer, and repeat, until the pointers cross.

OpenStudy (anonymous):

1) Make a copy of both your strings, the original as well as the anagram. 2) Sort both these strings, in descending order. This way all space characters (i.e. ' ') will be accumulated at the end of each string. [since the ASCII value of the space character is 32, which is less than the ASCII value of letters of the alphabet] 3) Use the following code to compare the two strings: int c=0; for(i=0; i>=0; i++) { if ((s[i]==anagram[i])&&(s[i]!=' ')) /*s and anagram are the names of the strings into which I copied the original 2 strings and sorted them*/ { if ((s[i+1]==' ')&&(anagram[i+1]==' ') { c=1; break; } if ((s[i+1]!=' ')&&(anagram[i+1]==' ') { break; } if ((s[i+1]==' ')&&(anagram[i+1]!=' ') { break; } } else break; } if (c==1) printf("The strings are anagrams"); else printf("The strings are not anagrams");

OpenStudy (anonymous):

@ktklown that's the check for a palindrome :-P Yeah do it zaw's way: Normalize the two strings, dealing with the upper/lowercase characters and the spaces as well as sorting the characters to allow the strings to be compared. Finally, compare the strings to test for anagrams.

OpenStudy (anonymous):

haha you're right, I mixed up anagrams with palindromes. My mistake.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!