Thread: converting a string to upper case

  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,897
    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,490
    is there a difference between size_t and int?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >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,897
    >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, 05:42 PM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. Xmas competitions
    By Salem in forum Contests Board
    Replies: 88
    Last Post: 01-03-2004, 02:08 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. A simple array question
    By frenchfry164 in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2001, 04:13 PM