I need some assistance in getting this program to perform correctly. It's suppose to take a sentence, break it up and return each word in pig latin. Right now, the program takes a sentence such as Jump start your morning and it returns Jumpay startay youray morningay. It should return umpjay tartsay ouryay orningmay. Can anybody tell me what I am doing wrong in my DisplayPigLatin function?
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <cstring>
using std::strtok;
using std::strlen;
#include <string>
using std::string;
const int LENGTH = 50;
void DisplayPigLatin( const char *);
int main()
{
char sentence[LENGTH];
char *tokenPtr;
cout << "Enter a sentence to be tokenized: \n\n";
cin.getline(sentence, LENGTH);
cout << "\n";
tokenPtr = strtok(sentence, " ");
while (tokenPtr != NULL)
{
DisplayPigLatin(tokenPtr);
tokenPtr = strtok(NULL, " ");
}
return 0;
}
void DisplayPigLatin( const char *tokenPtr )
{
char length = strlen(tokenPtr);
cout << tokenPtr[length];
for (int count = 0; count < length; count++)
cout << tokenPtr[length - (length - count)];
cout << "ay";
}