/*
 * Adapted from:
 * http://www.programmingsimplified.com/c/source-code/c-anagram-program
 */
#include <stdio.h>

#define MAX_CHARS	40
#define LETTERS		'z'-'a'+1 // 26

int check_anagram(char s1[], char s2[]) {
	int v1[LETTERS] = {0}, v2[LETTERS] = {0}, i = 0;

	for(i=0;s1[i] != '\0';i++) {
		v1[s1[i]-'a']++;
	}
	for(i=0;s2[i] != '\0';i++) {
		v2[s2[i]-'a']++;
	}
	for(i = 0; i < LETTERS; i++) {
		if (v1[i] != v2[i]) {
			return 0;
		}
	}

	return 1;
}

int main() {
	char s1[MAX_CHARS], s2[MAX_CHARS];
	int are_anagrams;

	printf("Enter first string\n");
	scanf("%s", s1);

	printf("Enter second string\n");
	scanf("%s", s2);

	are_anagrams = check_anagram(s1, s2);

	if (are_anagrams == 1)
		printf("\"%s\" and \"%s\" are anagrams.\n", s1, s2);
	else
		printf("\"%s\" and \"%s\" are not anagrams.\n", s1, s2);

	return 0;
}

