0

Just as the title says, I have text file that has virtually no uppercase letters in it, so all of the sentences don't look proper without the first letter capitalized. Here's my code so far:

    //This program reads an article in a text file, and changes all of the
//first-letter-of-sentence-characters to uppercase after a period and space.
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>//for toupper
using namespace std;

int main()
{
    //Variable needed to read file:
    string str;
    string input = str.find('.');


    //Open the file:
    fstream dataFile("eBook.txt", ios::in);
    if (!dataFile)
    {
        cout << "Error opening file.\n";
        return 0;
    }
    //Read lines terminated by '. ' sign, and then output:
    getline(dataFile, input, '. ');//error: no instance of overloaded function "getline"
                                   //matches the argument list
                                   //argument types are:(std::fstream, std::string, int)
    while (!dataFile.fail())
    {
        cout << input << endl;
        getline(dataFile, input);
    }
    //Close the file:
    dataFile.close();
    return 0;
}

. NOTE: I know there is no toupper keyword in my code yet. I don't know where to set it yet.

Sam Peterson
  • 107
  • 1
  • 9

1 Answers1

0

Instead of this

    getline(dataFile, input, '. ');
    while (!dataFile.fail())
    {
        cout << input << endl;
        getline(dataFile, input);
    }

You can change it to

    while(getline(dataFile, line, '.'))
    {
        for(auto &i : line )
        {
            if(!isspace(i))
            {
                i = toupper(i);
                break;
            }  
        }
        outFile<<line<<".";
    }

PS: I would prefer using RegEx for this kind of problems.

Ravi Shenoy
  • 467
  • 1
  • 4
  • 14