converting a string to upper case

This is a discussion on converting a string to upper case within the C++ Programming forums, part of the General Programming Boards category; hi, I was just wondering if there was a simple way of converting a string to all capital letters ??? ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    9

    Question converting a string to upper case

    hi,

    I was just wondering if there was a simple way of converting a string to all capital letters ??? eg a single for loop .... ?????

    Thank you for your time

    Craig

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    for ( size_t x = 0; x < strlen ( a ); x++ )
      a[x] = toupper ( a[x] );
    Simple enough?

    -Prelude
    My best code is written with the delete key.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    is there a difference between size_t and int?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >is there a difference between size_t and int?
    Yes, size_t is what strlen returns and size_t is usually defined as an unsigned type, thus causing a type mismatch in your loop condition if the counter variable is a regular int.

    -Prelude
    My best code is written with the delete key.

  5. #5
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    there is also a strupr() in string.h which does that in 1 line.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >there is also a strupr() in string.h which does that in 1 line.
    strupr isn't a standard function as far as I know.

    -Prelude
    My best code is written with the delete key.

  7. #7
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    >>strupr isn't a standard function as far as I know.

    Hmmm, thought that it was, but then everybody says that you are the MAN

  8. #8
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    >everybody says that you are the MAN

    Actually everybody says shes the WOMAN....

  9. #9
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    >>Actually everybody says shes the WOMAN....

    dude i've seen a lot saying "PRELUDE'S DA MAN"


    and i think she'll agree.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  2. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  3. Xmas competitions
    By Salem in forum Contests Board
    Replies: 88
    Last Post: 01-03-2004, 01:08 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-26-2003, 11:03 PM
  5. A simple array question
    By frenchfry164 in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2001, 03:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21