/* From: Douglas T. Martin, 05/25/2015 */
/* Written for any generic C compiler. Can run inside a project in an */
/* interactive development environment (IDE) or be compiled and made into an */
/* executable file and run from a command line. */
/* This file contains the following code: */
/* translate(): Function to convert a string of English text to pig Latin */
/* main(): The main program that requests the integer from the user */
/* and reports the resulting summation. */
/* Problem #2 */
/* Write a FUNCTION which takes in a String as a parameter and returns a Pig */
/* Latin version of that string. */
/* The program should be able to: */
/* 1) handle punctuation */
/* 2) Ignore numbers (i.e. if “500” is passed in, “500” is passed back) */
/* 3) Handle multiple sentences */
/* Pig Latin translation is simply taking the first letter of a “word” and */
/* appending that letter to the end of the word with “ay” added to the end as */
/* well. Example: “Alex, how did you do question 21?” should */
/* translate to “lexAy, owhay idday ouyay oday uestionqay 21?” */
#include <stdio.h> /* library functions for file input/output */
#include <stdlib.h> /* standard C library */
#include <stdint.h> /* library of integer types */
#include <string.h> /* library of string functions */
/* Declare functions below */
/* Declare global variables below */
static char inputBuffer[] = "Translate this English text to Pig Latin. 10 words total.\n"; /* 57 characters + \n */
static char outputBuffer[100]; /* Allocate enough space to add 'ay' to most words */
void translate (void)
{
int j; /* counter for input buffer position beginning of word */
int k; /* counter for input buffer position end of word */
int m; /* counter for output buffer position */
j = 0;
k = 0;
m = 0;
while (j < 57)
{
outputBuffer[j] = inputBuffer[j+1];
j++;
} // end of while loop
printf ("\nInput buffer contents: %s", inputBuffer
); printf ("\nOutput buffer contents: %s", outputBuffer
); return;
}
int main(void) /* Start of main loop */
{
int i; /* Counter variable */
for (i = 0; i < 100; i++)
{
outputBuffer[i] = " "; /* Initialize the output buffer */
}
translate();
return 0; /* return 0 to terminate main loop */
} /* end of main() loop */
/* This is what the output looks like when it runs: */
/* */
/* */