![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Posts: 1
Rep Power: 0
![]() |
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; } |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
__________________
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|