Newbie C++, need help in capitalisation

Discussion in 'C++' started by Robbo, Oct 12, 2004.

  1. Robbo

    Robbo Guest

    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
    Robbo, Oct 12, 2004
    #1
    1. Advertising

  2. Robbo

    JKop Guest

    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 = toupper( static_cast<unsigned char const>(in_str)
    );
    }
    }


    -JKop
    JKop, Oct 12, 2004
    #2
    1. Advertising

  3. Robbo

    Method Man Guest

    "JKop" <> wrote in message
    news:nYPad.33245$...
    > 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 = toupper( static_cast<unsigned char const>(in_str)
    > );
    > }
    > }
    >
    >


    You may need to use the 'ctype' facet from 'std::locale' to make this code
    portable.
    Method Man, Oct 12, 2004
    #3
  4. Robbo

    Howard Guest

    "JKop" <> wrote in message
    news:nYPad.33245$...
    > 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
    Howard, Oct 12, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jbl
    Replies:
    2
    Views:
    465
    Joe Smith
    Dec 16, 2004
  2. Patrick Hill

    asp login, I need help please!! Newbie

    Patrick Hill, Feb 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    684
    Rick Strahl [MVP]
    Feb 8, 2004
  3. Robbo
    Replies:
    11
    Views:
    721
    Joe Laughlin
    Oct 15, 2004
  4. =?Utf-8?B?Q2hyaXM=?=

    Help Help. I really need some help with this

    =?Utf-8?B?Q2hyaXM=?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    548
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
    Jan 31, 2007
  5. ElementX
    Replies:
    9
    Views:
    482
    RedGrittyBrick
    Oct 1, 2008
Loading...

Share This Page