Computer Chess Club Archives


Search

Terms

Messages

Subject: Handy for the new message format.

Author: Dann Corbit

Date: 15:10:00 10/29/03


/*
* Piglatin translator: simple rules
*    - every word starts with a vowel unless the word has no vowels
*    - 'y' is not a vowel
*    - one- and two-letter words and numbers are not Piglatinized
*    - the first part of the word up to the first vowel becomes the
*      word suffix, followed by 'ay'
*    - all words treated as monosyllabic
*    - punctuation is elided
*/

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>

typedef struct Piggy Piggy;
struct Piggy {
    char           *s;          /* word start */
    char           *e;          /* word end */
};

char            delim[UCHAR_MAX] = {0};

int             main(void)
{
    Piggy           p;
    char            buf[65535];
    char           *word;
    int             i,
                    j;

    for (i = 0, j = 0; i < UCHAR_MAX; i++) {
        if (isspace(i) || ispunct(i))
            delim[j++] = i;
    }

    while (fgets(buf, sizeof buf, stdin)) {
        for (word = strtok(buf, delim); word != 0; word = strtok(0, delim)) {
            if (strlen(word) < 3
                || isdigit((int) word[0])
                || strstr("the The THE", word) != 0) {
                printf("%s%s ", word, strstr("a A", word) ? "n" : "");
                continue;
            }
            p.e = word;
            p.s = strpbrk(word, "aeiouAEIOU");
            if (p.s == 0)
                p.s = &word[strlen(word)];
            printf("%s%.*say ", p.s, p.s - p.e, p.e);
        }
        printf("\n");
    }
    return 0;
}



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.