Skip to content

Instantly share code, notes, and snippets.

@antonijn
Created October 1, 2014 21:08
Show Gist options
  • Save antonijn/74e2c9f9ab0c4d6d716f to your computer and use it in GitHub Desktop.
Save antonijn/74e2c9f9ab0c4d6d716f to your computer and use it in GitHub Desktop.
enum sound {
CONSONANT,
SHORT_VOWEL,
LONG_VOWEL,
};
enum sound getsound(FILE *word)
{
int ch = fgetc(word);
if (isconsonant(ch))
return CONSONANT;
int nxt = fgetc(word);
if (nxt == EOF)
return LONG_VOWEL;
if (isvowel(nxt)) {
ungetc(nxt, word);
return LONG_VOWEL;
}
/* nxt is a consonant */
int nxtnxt = fgetc(word);
if (nxtnxt == EOF) {
ungetc(nxt, word);
return SHORT_VOWEL;
}
ungetc(nxtnxt, word);
ungetc(nxt, word);
if (isconsonant(nxtnxt))
return SHORT_VOWEL;
return LONG_VOWEL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment