January 19th, 2013, 02:04 PM
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?
January 19th, 2013, 02:07 PM
January 20th, 2013, 05:20 AM
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
and then convert lower to upper thus:
ch >= 'a' && ch <= 'z'
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.
ch = ch - 'a' + 'A' ;
Last edited by clifford; January 20th, 2013 at 05:34 AM.
January 21st, 2013, 06:05 AM
CS 101 homework?
taking an intro class Cathy?