currently only outputs the very last input string ex- Hello darkness, my old friend. good to see you again. output file- againway. What am missing? am i using fin.getline wrong? i figure its either that or, I'm way off. thanks any help or feedback is appreciated.
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <fstream>
usingnamespace std;
bool IsVowel(char letter)
{
switch (letter)
{
case'A':
case'E':
case'I':
case'O':
case'U':
case'Y':
case'a':
case'e':
case'i':
case'o':
case'u':
case'y':
returntrue;
default:
returnfalse;
}
}
void PigLatin(char *word)
{
ifstream fin;
fin.open("pigLatinFilein.txt");
ofstream fout;
fout.open("pigLatinFileout.txt");
string s1(word);
string s2;
if (IsVowel(word[0]) == true) s2 = s1 + "way";
else s2 = s1.substr(1) + s1[0] + "ay";
fout << s2 << " ";
}
int main()
{
ifstream fin;
fin.open("pigLatinFilein.txt");
ofstream fout;
fout.open("pigLatinFileout.txt");
char sentence[10000];
char *words;
fin.getline(sentence, 10000);
words = strtok(sentence, " ,.!:;""?");
while (words != NULL)
{
PigLatin(words);
words = strtok(NULL, " ,.!:;""?");
}
fin.close();
return 0;
}
//1. If a word starts with a consonant and a vowel, put the first letter of the word at the end of the word and add "ay."
//Example: Happy = appyh + ay = appyhay
//2. If a word starts with a vowel add the word "way" at the end of the word.
//Example: Awesome = Awesome +way = Awesomeway
Your main problem is opening the files again in PigLatin. It would be best if it just returned the modified string. Also, you aren't including the double-quote in your delimiters properly. To include a double-quote inside double-quotes you need to precede it with a backslash.