As the title says: a C function for detecting anagrams.
Returns true if both strings are anagrams, returns false otherwise.
isAnagram() function in C
Ancient Dragon
commented:
Very good, and a unique way of doing it :)
+36
/* Check if s1 and s2 are anagrams of each other */
int isAnagram(const char *s1, const char *s2)
{
int ha[CHAR_MAX] = {0};
int i;
while(*s1 && *s2) {
ha[*s1++]++;
ha[*s2++]--;
}
if(*s1 || *s2) return 0;
for(i=0; i<CHAR_MAX; ++i) {
if(ha[i]) return 0;
}
return 1;
}
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
mvmalderen
2,072
Postaholic
Dave Sinkula
2,398
long time no c
Team Colleague
mvmalderen
2,072
Postaholic
Dave Sinkula
2,398
long time no c
Team Colleague
mvmalderen
commented:
Thanks for the demonstration :)
+24
Aia
commented:
A little demostration goes a long way
+6
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.