Below is the pig latin example from the first day we discussed it. Please know that it has unresolved issues that we will address next class.

pig.c

#include <stdio.h>
#include <unistd.h>
#include <string.h>

// read input
// pig latinify
// - find a vowel
// - reorder and ayify
// write it out

const char *findVowel(const char* word) {
  return strpbrk(word, "aeiouAEIOU");
}

void reorderAndAyify(const char* word) {
  const char *vowel = findVowel(word);

  printf("%s", vowel); // print the "ig"
  write(1, word, vowel - word); // print the "p"
  printf("ay"); // print ay
}

int main (int argc, const char *argv[]) {
  for (int i = 0; i < argc; i++) {
    reorderAndAyify(argv[i]);    
    puts("");
  }
  return 0;
}

Copyright © 2025 John Hott, portions Luther Tychonievich.
Released under the CC-BY-NC-SA 4.0 license.
Creative Commons License