I created a program that converts English words into pig Latin (part of my class). Currently it converts only one word: "hello"->"elloyay".
Out of my own curiosity I wanted to enable the possiblity reading multiple words separated by spaces and then have each one of these words converted accordingly.
More technically, use substr to grab a word between two sequential spaces. the input will be broken by substr to separated words. Each word in a time will be parsed by my make_pig_latin parser and will replace her corresponding word in that string array.
e.g.: the input "hello yellow fellow" will result in the output "elloyay ellowyay ellowyay".
Can anyone let me know if my coding to accomplish this task is on the right track. I keep crashing in runtime and I think it is due to the array of strings not being created correctly. But I am not fully sure about it.
Any help would be appreciated.
int main()
{
string word;
string word_List[] = { word };
cout << "Enter your story (Please include spaces between each word): ";
getline(cin, word);
char c = word[0];
int i = 0;
int j = 0;
int k = i;
int l = 0;
while (i < (word.length() - 1))
{
if (word[i] = '\n')
{
string new_Word = word.substr(j, k);
string test_Pig = make_Pig_Latin(new_Word);
word_List[l] = test_Pig;
l == l + 1;
j == i + 1;
i == k + 1;
}
if (word[i] = '.')
{
i = word.length() + 1;
}
}
cout << "The Story In Pig Latin Is " << word_List << endl;
cin.ignore();
cin.get();
return EXIT_SUCCESS;
}
Extra information for the user to add: complete error line, compiler+version used, OS used.
std::vector.word_Listcan only hold a singlestring, raw arrays have a fixed compile time size.if(word[i] = '.')should beif(word[i] == '.'). And your array only has one slot.