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?
//**********************
//This program takes the first letter of each sentence in a text
//file and converts it into a capital letter.
//**********************
//**********************
//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
//**********************
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
//**********************
//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>
usingnamespace 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
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
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.