Capitalization

I need help with reading contents from file1(which is all uppercase) and then changing all letters to lowercase except the first letter of each sentence, which would be made(remain?)uppercase. Then output this to file2. This is what I have that deals with this particular section of code. Any hints on how I can get the desired output are greatly appreciated.


1
2
3
4
5
6
7
8
9
  while (inputFile)
	{	
	     inputFile.get(ch);
	     while (!inputFile.eof())
	     {
	          outputFile.put(tolower(ch));
		  inputFile.get(ch);
	     }
	}
Something like:

1
2
3
4
5
6
7
    bool inWord = false;

    while (inputFile.get(ch))
    {
        outputFile.put(inWord ? tolower(ch) : ch);
        inWord = !isspace(ch);
    }
State machine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Assume beginning of sentence (bool)
char ch;
while ( inputFile.get(ch) ) {
  IF ch is alphabetic // case counts only for text
  THEN
    IF at begin
    THEN set not at begin // change state at begin of sentence
    ELSE ch = tolower(ch)

  IF '.' == ch // change state at end of sentence
  THEN set at begin

  outputFile.put( ch );
}

Extra dots will need more attention though.
Thanks for your feedback. This code was a step in the right direction. But it capitalized the first letter of every word, not the first letter of every sentence.

1
2
3
4
5
6
7
     bool inWord = false;

    while (inputFile.get(ch))
    {
        outputFile.put(inWord ? tolower(ch) : ch);
        inWord = !isspace(ch);
    }


I kinda followed the pseudo code of the other explanation. But not well enough to know how to put it into practice.
Thanks for your feedback. This code was a step in the right direction. But it capitalized the first letter of every word, not the first letter of every sentence.

It should be pretty clear from the pseudo code and the sample provided that you need to keep track of state and take action according to what that state is. Give it a shot and post the code if you're having trouble.
I almost gave up, but I finally figured it out!! I had to just relax and think it through step by step very slowly. Thanks again for your feedback though. It was very helpful.
Topic archived. No new replies allowed.