How the heck???

English to Piglatin Program?

Posted 08 July 2010 - 08:36 PM

I am trying to do this:
You are to write a program that will input English text translate it into Pig Latin, then output the result to a file

Pig Latin is an invented language formed by transforming each word according to the following rules:
1.If the word starts with a vowel ('a', 'e', 'i', 'o', 'u', or 'A, 'E', 'I', 'O', 'U') or does not contain a vowel, its Pig Latin equivalent is formed by just adding the suffix “way”.
2.If the word starts with a consonant (any letter that is not a vowel) and contains a vowel its Pig Latin equivalent is formed by moving the initial consonant string (that is all letters up to the first vowel) from the beginning of the word to the end and then adding the suffix “ay”.
3.If a word is transformed by rule 2) and starts with an upper case character (consonant), its Pig Latin equivalent also starts with an upper case character (vowel) and the consonant is changed to lower case.

A word will be taken to mean any consecutive sequence of letters, i.e. you don't have to check that the sequence is actually an English word. A word is terminated by any non-letter (e.g white space, punctuation mark, etc.).

Made this outline:
int main( )
{
declare el, pl as strings to store an English line, Pig Latin line;

prompt for and get English line (use gets);
while (line is not equal to “!!!”)
{
translate(el, pl);
output Pig Latin line to the screen and to a file;
prompt for and get English line (use getline);
}

initialize current positions ep, pp to be the beginning of el, pl, i.e. initialize them to 0;
while (not at end of el)
if (character at current position in el is a letter)
{
extract word from el that starts from current position and store in ew;
translate word ew to Pig Latin and store in pw;
copy pw at current end of pl;
make sure ep, pp are now set to positions just past the word;
}
else /* character at current position in el is not a letter */
{
copy this character unchanged to current position in pl;
increment ep, pp;
}

Re: English to Piglatin Program?

Posted 09 July 2010 - 12:43 AM

yes your syntax is horrible that that isn't a big deal you can prob fix that on you own (like makes sure each command is terminated properly). When you initialize your character arrays, you don't have a size so your compile doesn't know how much memory to put aside for your array. so when you declare/initialize your array, make sure you give it a size. If you don't know the size give it a decent size that you know will prob not be used like if your just going to input words to the array use like 15-20 for the size and that could be over doing it to some people. in your while loop, i am assuming you are looking for the line terminating character. Well to access what is stored in the array you have to select the address. an array is a series of memory address side by side. array[0] is the first one and it keeps on going from there all the way up to array[x] (where x is the size you designated minus one). that tells the compiler that hey at address array[0] put 'C'. I hope this is helping. in the brackets when accessing elements in an array you always use numbers. you want the position x of the array (array[x]) so instead of "while(!array[/0])" do something more along the lines of:

//you could also have an int datat type to store where the null terminator was located so you can use that position for future reference
int nLocation;
for(int i=0;array[i] != '/0';i++)
{
if(iarray[i]=='/0')
nLocation=i;
//the code you want to do while the element you are accessing is not the null terminator
}

another good way to move elements in an array is to have a seperate place holder something like this

//this is used to hold the first character of the c string
char First=array[0];
//because we got the location of the null terminator earlier, we can use it now
for(int i=0;i<nLocation;i++)
array[i]=array[i+1];
//now we can put the first letter in the back
array[nLocation-1]=First;