Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Newbie C++, need help in capitalisation

Reply
Thread Tools

Newbie C++, need help in capitalisation

 
 
Robbo
Guest
Posts: n/a
 
      10-12-2004
Hi, I need to know how to turn a string into Upper case letters even
if the input is in lower.

E.g. say i was entering a name in a program and i typed john smith, i
need it to come out as John Smith.

Any idea on how this is done?

Many Thanks
 
Reply With Quote
 
 
 
 
JKop
Guest
Posts: n/a
 
      10-12-2004
Robbo posted:

> Hi, I need to know how to turn a string into Upper case letters even
> if the input is in lower.
>
> E.g. say i was entering a name in a program and i typed john smith, i
> need it to come out as John Smith.
>
> Any idea on how this is done?
>
> Many Thanks
>



Half-baked code:



#include <cstddef>
#include <cstring>


void ChangeToAllUppercase(char* const in_str)
{
std::size_t const length = std::strlen(in_str);

for (std::size_t i = 0; i < length; ++i)
{
in_str[i] = toupper( static_cast<unsigned char const>(in_str[i])
);
}
}


-JKop
 
Reply With Quote
 
 
 
 
Method Man
Guest
Posts: n/a
 
      10-12-2004

"JKop" <(E-Mail Removed)> wrote in message
news:nYPad.33245$(E-Mail Removed)...
> Robbo posted:
>
> > Hi, I need to know how to turn a string into Upper case letters even
> > if the input is in lower.
> >
> > E.g. say i was entering a name in a program and i typed john smith, i
> > need it to come out as John Smith.
> >
> > Any idea on how this is done?
> >
> > Many Thanks
> >

>
>
> Half-baked code:
>
>
>
> #include <cstddef>
> #include <cstring>
>
>
> void ChangeToAllUppercase(char* const in_str)
> {
> std::size_t const length = std::strlen(in_str);
>
> for (std::size_t i = 0; i < length; ++i)
> {
> in_str[i] = toupper( static_cast<unsigned char const>(in_str[i])
> );
> }
> }
>
>


You may need to use the 'ctype' facet from 'std::locale' to make this code
portable.


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      10-12-2004

"JKop" <(E-Mail Removed)> wrote in message
news:nYPad.33245$(E-Mail Removed)...
> Robbo posted:
>
> > Hi, I need to know how to turn a string into Upper case letters even
> > if the input is in lower.
> >
> > E.g. say i was entering a name in a program and i typed john smith, i
> > need it to come out as John Smith.
> >
> > Any idea on how this is done?
> >
> > Many Thanks
> >

>
>
>>

> void ChangeToAllUppercase(char* const in_str)
> {


JKop: Umm, actually, that's not what was asked. Read it again: he wanted
to turn, for example, "john smith" into "John Smith". That requires using
toupper(), all right, but only on specific characters.

Robbo: I believe that the std::string class has member functions that will
locate specific delimiters, or at least to locate or return sub-strings in
the string using specific delimiters. Once you've located a specific
"token" (e.g., "smith"), simply call toupper() on the first character of
that. (And of course, just call toupper() on the very first character as
well.) Look into the string class members for more info. (I'm not up on
its member functions personally, sorry.)

If you have troubles with coding that, post what you accomplish and we can
help with specific problems with the code.

-Howard




 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re_---need help Network Adapters!!!! NEED HELP!!!! hedayatniac@gmail.com Computer Support 4 08-13-2006 01:03 AM
USR2216 WiFi card causes Win XP to crash - newbie need help! David Leslie Wireless Networking 3 01-22-2005 05:17 PM
A novice (newbie) in need of help jbl Perl 2 12-16-2004 06:22 AM
Newbie C++, need help in capitalisation Robbo C++ 11 10-15-2004 10:18 PM
asp login, I need help please!! Newbie Patrick Hill ASP .Net 3 02-08-2004 08:18 AM



Advertisments