Convert char* to upper case

Discussion in 'C Programming' started by RishiD, Feb 16, 2007.

  1. RishiD

    RishiD Guest

    Hi,

    For some reason I am blanking this Friday morning. I have a class
    constructor call Point as shown below. Trying to figure out how I can
    make the arguments passed in all upper case before I set the member
    variables.

    Thanks for the insight.

    RishiD

    Point(const char* name,
    const char* description,
    const char* iomid,
    const char* address,
    const char* type,
    Event* event)
    {
    m_strName = name;
    m_strDesc = description;
    m_strAddress = address;
    m_strType = type;
    m_strParentName = iomid;
    m_Event = event;
    }
     
    RishiD, Feb 16, 2007
    #1
    1. Advertising

  2. RishiD <> wrote:

    > For some reason I am blanking this Friday morning.


    Starting with posting code that seems a little like C++ to
    comp.lang.c? (It has indeed been a lengthy week.)

    > I have a class
    > constructor call Point as shown below. Trying to figure out how I can
    > make the arguments passed in all upper case before I set the member
    > variables.


    There's no builtin C function to do this, but you could write one
    using the builtin toupper() for characters. Alternatively, there
    might be a C++ way to do this, if you are indeed writing C++ as it
    seems.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Feb 16, 2007
    #2
    1. Advertising

  3. RishiD said:

    > Hi,
    >
    > For some reason I am blanking this Friday morning. I have a class
    > constructor call Point as shown below.


    ....which makes me think you're using C++, so I've cross-posted this
    reply to comp.lang.c++, and set followups to that group.

    > Trying to figure out how I can
    > make the arguments passed in all upper case before I set the member
    > variables.


    In C, you'd probably write a function that calls toupper() in a loop -
    but in C++ there may be a more C++y way to do it.

    [Remainder of your article retained, for clc++'s convenience. Hi guys,
    long time no see.]

    >
    > Thanks for the insight.
    >
    > RishiD
    >
    > Point(const char* name,
    > const char* description,
    > const char* iomid,
    > const char* address,
    > const char* type,
    > Event* event)
    > {
    > m_strName = name;
    > m_strDesc = description;
    > m_strAddress = address;
    > m_strType = type;
    > m_strParentName = iomid;
    > m_Event = event;
    > }


    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at the above domain, - www.
     
    Richard Heathfield, Feb 16, 2007
    #3
  4. Christopher Benson-Manica wrote:
    >RishiD <> wrote:
    >>... Trying to figure out how I can
    >> make the arguments passed in all upper case before I set the member
    >> variables.

    >
    >There's no builtin C function to do this, but you could write one
    >using the builtin toupper() for characters. Alternatively, there
    >might be a C++ way to do this, if you are indeed writing C++ as it
    >seems.


    [OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
    services provided in <ctype>

    Roberto Waltman

    [ Please reply to the group,
    return address is invalid ]
     
    Roberto Waltman, Feb 16, 2007
    #4
  5. RishiD wrote:

    > Hi,
    >
    > For some reason I am blanking this Friday morning. I have a class
    > constructor call Point as shown below. Trying to figure out how I can
    > make the arguments passed in all upper case before I set the member
    > variables.
    >
    > Point(const char* name,
    > const char* description,
    > const char* iomid,
    > const char* address,
    > const char* type,
    > Event* event)
    > {
    > m_strName = name;
    > m_strDesc = description;
    > m_strAddress = address;
    > m_strType = type;
    > m_strParentName = iomid;
    > m_Event = event;
    > }


    #include <ctype.h>

    void up(char *q)
    {
    unsigned char c;

    while (*q) { c = *q; *q = toupper(c); q++; }

    return;
    }

    Also your function specifies "const char *". You might want to adhere to that.
     
    Christopher Layne, Feb 16, 2007
    #5
  6. Roberto Waltman wrote:

    > [OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    ^^^^^^^^^^^^^^^^^^

    ???
     
    Christopher Layne, Feb 16, 2007
    #6
  7. RishiD

    Eric Sosman Guest

    Christopher Layne wrote On 02/16/07 11:07,:
    > Roberto Waltman wrote:
    >
    >
    >>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    >
    > ^^^^^^^^^^^^^^^^^^
    >
    > ???


    Go back and read Roberto's message again, this time
    paying attention to the text he quoted and responded to.

    --
     
    Eric Sosman, Feb 16, 2007
    #7
  8. Christopher Layne wrote:

    >Roberto Waltman wrote:
    >> [OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    > ^^^^^^^^^^^^^^^^^^


    Off-topic, wearing a C++ hat:
    From Josuttis "The C++ Standard Library", 1st ed, 10th printing, page
    716.

    The facet ctype is a template class parameterized with a character
    type...
    ....
    Table 14.16. Services defined by the ctype<charT> Facet
    ....
    ct.toupper(beg,end) Converts each letter in the range between beg and
    end by replacing the letter with the result of toupper()

    Roberto Waltman

    [ Please reply to the group,
    return address is invalid ]
     
    Roberto Waltman, Feb 16, 2007
    #8
  9. Eric Sosman wrote:
    > Christopher Layne wrote On 02/16/07 11:07,:
    > > Roberto Waltman wrote:
    > >
    > >
    > >>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    > >
    > > ^^^^^^^^^^^^^^^^^^
    > >
    > > ???

    >
    > Go back and read Roberto's message again, this time
    > paying attention to the text he quoted and responded to.


    The C++ part? toupper(begin,end) is new to me if it's valid at all,
    regardless of which language is used.
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Feb 16, 2007
    #9
  10. Eric Sosman wrote:
    > Christopher Layne wrote On 02/16/07 11:07,:
    > > Roberto Waltman wrote:
    > >
    > >
    > >>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    > >
    > > ^^^^^^^^^^^^^^^^^^
    > >
    > > ???

    >
    > Go back and read Roberto's message again, this time
    > paying attention to the text he quoted and responded to.


    The C++ part? toupper(begin,end) is new to me if it's valid at all,
    regardless of which language is used.
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Feb 16, 2007
    #10
  11. Roberto Waltman wrote:
    > Christopher Layne wrote:
    >
    > >Roberto Waltman wrote:
    > >> [OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

    > > ^^^^^^^^^^^^^^^^^^

    [un-snip]
    > >> services provided in <ctype>

    >
    > Off-topic, wearing a C++ hat:
    > From Josuttis "The C++ Standard Library", 1st ed, 10th printing, page
    > 716.
    >
    > The facet ctype is a template class parameterized with a character
    > type...
    > ...
    > Table 14.16. Services defined by the ctype<charT> Facet
    > ...
    > ct.toupper(beg,end) Converts each letter in the range between beg and
    > end by replacing the letter with the result of toupper()


    Oh, provided by a ctype class, not provided by any <ctype> header...?
     
    =?utf-8?B?SGFyYWxkIHZhbiBExLNr?=, Feb 16, 2007
    #11
  12. Eric Sosman wrote:

    > Go back and read Roberto's message again, this time
    > paying attention to the text he quoted and responded to.


    You are correct. I thought he was responding in general, not specifically to
    the C++ part. Part of that may be due to the fact that I don't generally
    think in any C++ mode while i'm in this NG.
     
    Christopher Layne, Feb 16, 2007
    #12
  13. "Christopher Layne" <> wrote in message
    news:...
    > RishiD wrote:
    >
    >> Hi,
    >>
    >> For some reason I am blanking this Friday morning. I have a class
    >> constructor call Point as shown below. Trying to figure out how I can
    >> make the arguments passed in all upper case before I set the member
    >> variables.
    >>
    >> Point(const char* name,
    >> const char* description,
    >> const char* iomid,
    >> const char* address,
    >> const char* type,
    >> Event* event)
    >> {
    >> m_strName = name;
    >> m_strDesc = description;
    >> m_strAddress = address;
    >> m_strType = type;
    >> m_strParentName = iomid;
    >> m_Event = event;
    >> }

    >
    > #include <ctype.h>
    >
    > void up(char *q)
    > {
    > unsigned char c;
    >
    > while (*q) { c = *q; *q = toupper(c); q++; }
    >
    > return;
    > }
    >
    > Also your function specifies "const char *". You might want to adhere to
    > that.


    Especially since this can cause bad things to happen using the above code:
    char *ptr = "test";
    up(ptr);
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Software Reuse Project
     
    Fred Kleinschmidt, Feb 16, 2007
    #13
  14. "Harald van D?k" wrote:
    >Roberto Waltman wrote:
    >> ... C++ stuff ...
    >> ct.toupper(beg,end) Converts each letter in the range between beg and
    >> end by replacing the letter with the result of toupper()

    >
    >Oh, provided by a ctype class, not provided by any <ctype> header...?


    [Still-off-topic] Beginning to get beyond my depth, (no books at hand
    now.) I believe it is provided by the standard headers, but somehow
    linked to (buried under?) the locale selection mechanisms.

    There is also a toupper(c, loc) that will convert c to upper case IFF
    it is a lower case character in locale loc.

    Roberto Waltman

    [ Please reply to the group,
    return address is invalid ]
     
    Roberto Waltman, Feb 16, 2007
    #14
    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. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,211
    Richard Bos
    Dec 14, 2004
  2. Replies:
    3
    Views:
    368
    Keith Thompson
    Mar 17, 2006
  3. Richard Heathfield

    Re: Convert char* to upper case

    Richard Heathfield, Feb 16, 2007, in forum: C++
    Replies:
    0
    Views:
    689
    Richard Heathfield
    Feb 16, 2007
  4. penny
    Replies:
    28
    Views:
    2,890
    Charlton Wilbur
    Mar 10, 2008
  5. BlackHelicopter
    Replies:
    0
    Views:
    561
    BlackHelicopter
    Jan 31, 2013
Loading...

Share This Page