| | |
How To Capitalize ALL Letters using Toupper function
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
I have the following code which I have been trying get to output ALL capital letters using the toupper function.
My code will build successfully, however all the letters are still lower case when ever I type.
PLEASE HELP ME UNDERSTAND WHAT I AM DOING WRONG!
The following is the code I have gotten to so far, but I need to know where to place the toupper function. Everytime I try to associate it with char c I do something wrong.
-------------------------------------------------------------------------------------------
My code will build successfully, however all the letters are still lower case when ever I type.
PLEASE HELP ME UNDERSTAND WHAT I AM DOING WRONG!
The following is the code I have gotten to so far, but I need to know where to place the toupper function. Everytime I try to associate it with char c I do something wrong.
-------------------------------------------------------------------------------------------
cpp Syntax (Toggle Plain Text)
#include <stdio.h> #include <iostream> using namespace std; int main (int argc, char *argv[], char **env) { char c, lastc = ' ' ; c = cin.get() ; do { cout.put(c) ; c = cin.get() ; } while ( !cin.eof()) ; return 0; }
Last edited by WaltP; Oct 15th, 2009 at 11:09 pm. Reason: Added CODE tags -- with all the help about them, how could you miss using them????
•
•
Join Date: Oct 2009
Posts: 13
Reputation:
Solved Threads: 0
0
#3 Oct 15th, 2009
cpp Syntax (Toggle Plain Text)
#include <stdio.h> #include <iostream> using namespace std; int main (int argc, char *argv[], char **env) { char c, lastc = ' ' ; [B]c = toupper(cin.get());[/B] do { cout.put(c) ; c = cin.get() ; } while ( !cin.eof()) ; return 0; }
This one is really frustrating me, I think that I am thinking too hard about it though.
Any other pointers???
Last edited by WaltP; Oct 15th, 2009 at 11:11 pm. Reason: And again, Added CODE tags -- look them up!
1
#4 Oct 15th, 2009
Remove that line again and put it inside your loop. Put a
So your loop-block should look like this:
also code-tags. Learn to use them.
cout << c; inside your loop and remove the other cin/cout statements.So your loop-block should look like this:
C++ Syntax (Toggle Plain Text)
{ c = toupper(cin.get()); cout << c; }
also code-tags. Learn to use them.
Last edited by niek_e; Oct 15th, 2009 at 3:43 am.
-1
#5 Oct 15th, 2009
You can also use this code snippet if you are confused..
char response[256];
cout<<"Enter a word.."<<endl;
---------------------------------------------
<cin.getline(response,256);
for(int i=0;i<response.length();i++){
response[i]=toupper(response[i]);
}>
-----------------------------------
This code converts 'response' to capital letters.
This is just for the knowing,anyway.
char response[256];
cout<<"Enter a word.."<<endl;
---------------------------------------------
<cin.getline(response,256);
for(int i=0;i<response.length();i++){
response[i]=toupper(response[i]);
}>
-----------------------------------
This code converts 'response' to capital letters.
This is just for the knowing,anyway.
3
#6 Oct 15th, 2009
Or a real C++ solution:
@tkud: code-tags: learn to use them
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <algorithm> #include <string> struct upper { int operator() ( int c ) { return toupper ( static_cast<unsigned char> ( c ) ); } }; int main(){ std::string str = ""; std::getline(std::cin, str); std::transform(str.begin(),str.end(),str.begin(),upper()); std::cout << str; return 0; }
@tkud: code-tags: learn to use them
![]() |
Similar Threads
- C++ word duplication (C++)
- tolower function does not work on certain letters (C++)
- function program...help! (C++)
- toupper function (C++)
- trouble with double linked list (C++)
- Frequency of characters entered. (C)
- String conversion... (C++)
- Help with Program I wrote (C++) (C++)
- sentence capitalizer (C++)
Other Threads in the C++ Forum
- Previous Thread: Convert minutes to time
- Next Thread: stack n list output problem
Views: 483 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






