#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    Convert text to all uppercase letters


    How do I start a program to convert a text of lower and uppercase letters to all uppercase letters?
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,242
    Rep Power
    2222
    Search on toupper.
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    The standard function toupper() converts a single character to upper-case (having no effect on non-alpha characters or those already upper case).

    To convert a string, you need to iterate each character of the string, calling toupper() for each one. Strings are terminated by a null character '\0', you use that to test for completion.

    You might convert in place or copy the converted characters to a new string; that's a design issue for you to decide, or is possibly specified for you in the assignment is this if homework?

    If using toupper() is not permitted in the assignment, then you can (for the ASCII character set at least) test for lower case by the expression
    Code:
    ch >= 'a' && ch <= 'z'
    and then convert lower to upper thus:
    Code:
    ch = ch - 'a' + 'A' ;
    however note that toupper() is more likely to be implemented to cope with local specific alphabets and accented characters - that is somewhat more complex. Also toupper() will in theory handle some arcane and unusual character encodings where the alpha characters are not contiguous, but to be honest that is a pedantic point, you are never likely to encounter such horrors in modern computing.
    Last edited by clifford; January 20th, 2013 at 06:34 AM.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    1
    Rep Power
    0

    CS 101 homework?


    taking an intro class Cathy?

IMN logo majestic logo threadwatch logo seochat tools logo