Hello everyone, been coming here a lot this past year since I started learning, but this is the first time I have posted a question.
I have been doing this program for class that asks to convert a files that's filled with sentences that are mixed with upper and lower case letters. The program is supposed to open the file, convert letter to their proper format, and save them in a separate file. The problem is that it always repeats the last character twice, even with the rest of the file coming out right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string unfmat;
string fmat;
char ch;
ifstream inFile;
ifstream inFile2;
cin >> unfmat;
cin >> fmat;
ofstream outFile(fmat);
inFile.open(unfmat);
if (inFile)
{
inFile.get(ch);
outFile.put(toupper(ch));
while (inFile)
{
inFile.get(ch);
outFile.put(tolower(ch));
if (ch == '.')
{
inFile.get(ch);
outFile.put(ch);
if (ch == '\n')
{
inFile.get(ch);
outFile.put(toupper(ch));
}
if (ch == ' ')
{
inFile.get(ch);
outFile.put(toupper(ch));
}
}
}
}
inFile.close();
outFile.close();
inFile2.open(fmat, ios::in);
if (inFile2)
{
inFile2.get(ch);
while (inFile2)
{
cout << ch;
inFile2.get(ch);
}
}
inFile2.close();
system("Pause");
return 0;
}
|
The Input file looks like this:
SiMple SeNtence HERe.
sEntEnCe SpannInG tWO
lInEs HERE.
tWO sEnTeNCEs. iN tHe Same LiNE.
TWo and halF. SeNTenceS in ThE. samE liNE
The Output comes out like this:
Simple sentence here.
Sentence spanning two
lines here.
Two sentences. In the same line.
Two and half. Sentences in the. Same linee
No matter what the final character is, the program repeats it.
Also on a side note, I have to turn this in through an CodeLab as part of my class and the results are even weirder. The program actually works correctly, but makes a new line 3 times for some odd reason during output.