#include <stdio.h> #include <string.h> int charcmp(const char *c1, const char *c2) { return(*c1-*c2); } int main(int argc, char **argv) { char word[256], canon[256]; for (;;) { if (gets(word) == NULL) break; strcpy(canon, word); qsort(canon, strlen(canon), sizeof(char), charcmp); #ifdef PLAIN_ANAGRAMS printf("%s=%s\n", canon, word); #else /* Letterbanking */ { char c, *cp = canon; for (;;) { putchar(c = *cp++); while (c == *cp) cp++; // skip repeated letters if (*cp == '\0') break; } } printf("=%s\n", word); #endif } return(0); }