using toupper

Pages: 12
it seems easy enough but I am having difficulty using to upper in this program I am writing. I need to convert the first letter of each sentence to an upper cause using a void param call to function and no arrays. Can anyone help?
What do you have so far?
//**********************
//This program takes the first letter of each sentence in a text
//file and converts it into a capital letter.
//**********************

#include <iostream>
#include <fstream>
#include <cctype>
#include <cstdlib>
using namespace std;

//**********************
//Function: process_text
//Purpose: reads in the characters from a data file by ifstream until
// the end of the text and capitalizes the first letter
// of every sentence
//Params: inp_file (the input file)
//Uses: ifstream and cctype
//**********************

void process_text(ifstream& inp_file);

int main()
{
ifstream fin;

fin.open("sentence.dat");
if(fin.fail())
{
cout << "Your input file failed to open" << endl;
exit(1);
}

process_text(fin);

return 0;
}

void process_text(ifstream& inp_file)
{
char n;
inp_file.get(n);

while(! inp_file.eof())
{
if(n=='.')
{
inp_file.get(n);
cout << static_cast<char>(toupper(n));
}else{
cout << n;
}
inp_file.get(n);
}
}
I am having trouble with the void part. I want it to recognize the first letter of the sentence but I am not sure how to get from where I am to there cause right now it is just cutting out the period
sorry it didn't come out indented right
That's because you didn't use code tags:

http://cplusplus.com/articles/firedraco1/
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
//**********************
//This program takes the first letter of each sentence in a text
//file and converts it into a capital letter.
//
//Krystine Garcia
//18 February 2010
//**********************

#include <iostream>
#include <fstream>   
#include <cctype>
#include <cstdlib>
using namespace std;  
         
//**********************
//Function: process_text
//Purpose: reads in the characters from a data file by ifstream until
//         the end of the text and capitalizes the first letter
//         of every sentence
//Params: inp_file (the input file)
//Uses: ifstream and cctype
//**********************

void process_text(ifstream& inp_file);
 
int main()
{
        ifstream fin;
        
        fin.open("sentence.dat");
        if(fin.fail())
        {
                cout << "Your input file failed to open" << endl;
                exit(1);
        }
 process_text(fin);  

        return 0;
}

void process_text(ifstream& inp_file) 
{
        char n;
        inp_file.get(n);
        
        while(! inp_file.eof())
        {
                if(n=='.')
                {
                        inp_file.get(n);
                        cout << static_cast<char>(toupper(n));
                }else{
                        cout << n;
                }
                inp_file.get(n);
        }
}


okay i hope this works. and i don't know what the different compilers are. I am doing this on my laptop using pico to write the program
what compiler are you using?
Last edited on
i don't know what the different compilers are
Thats okay... do you have any idea what it might be just looking at it?
What im asking you is what is the name of your compiler.
i don't know. what are the different compilers?
Yes in Dev-C++ which is the compiler I am using there is a function which does just that.
I wish I could say that I knew that is what I am using but I do not know. This is kind of my first computer class I am taking so its all foreign to me still unfortunately. And thanks I really appreciate the help
You don't know the name of what your using to write programs with?
no i dont. I just know it as pico... looking it up would probably explain it better then i could
okay I don't know cause when I looked it up it says its a programming language of its own so I have no idea
Thats ok. You should ask about a book on pico that would help you understand it better.
well my professor told me to use it to write my programs in my C++ class
so i take it you have no idea how to help me
Pico is not a programming language, it is basically a text editor (like notepad). You are probably using g++ to compile your programs, but that's kind of irrelevant here.

The only problem I see with that is what happens if the '.' is just before the end of a line, when the next character would be a '\n' or if there are spaces after the '.' Try looking at some of the other function in cctype (I think that's where toupper is) and see if you can find one that would help you.
Pages: 12