Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 18th, 2006, 6:51 AM   #1
LHead
Newbie
 
Join Date: Feb 2006
Posts: 1
Rep Power: 0 LHead is on a distinguished road
toupper help needed

i have written this code and need it to read a file and change the first charachter in a sentence to upper case.
it reads the file and changes the first letter of the program but not after a full stop.
i dont know why! or how to fix it! please help!

void uppercase(void)
{

int charcount=0;
char ch, lastchar;
bool Fullstopflag = false;

ifstream input("test.txt"); // **** Open the Input file ****
if(input.fail()) // **** If a problem opening the file ****
{
cerr<<"Error opening File:\n"; //**** Display an error message ****

exit(1); // **** End the program ****
}
while(!input.eof())
{
input.get(ch);
charcount++;

if ((Fullstopflag==true)&&(ch!=' '))
{
ch = toupper(ch);
Fullstopflag = false;
}

if (charcount==1)ch=toupper(ch);
if((lastchar==13)&&(ch!=' ')&&(Fullstopflag== true)) ch=toupper(ch);

cout<<ch;
}
lastchar=ch;



}
LHead is offline   Reply With Quote
Old Feb 18th, 2006, 6:53 AM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
I didn't have a close look at your code, but I don't see you setting charcount to 0 at the end of the loop.

Please use code tags next time, it makes code easier readable.
Polyphemus_ is offline   Reply With Quote
Old Feb 18th, 2006, 7:21 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Linky Dinky One
Linky Dinky Two
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:44 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC