Convert characters.
#include <ctype.h>
int __toascii( int c );
int tolower( int c );
int _tolower( int c );
int toupper( int c );
int _toupper( int c );
c | Character to be converted |
The __toascii, tolower, _tolower, toupper, and _toupper routines and their associated macros convert a single character, as described below:
Function | Macro | Description |
__toascii | __toascii | Converts c to ASCII character |
tolower | tolower | Converts c to lowercase if appropriate |
_tolower | _tolower | Converts c to lowercase |
toupper | toupper | Converts c to uppercase if appropriate |
_toupper | _toupper | Converts c to uppercase |
The __toascii routine sets all but the low-order 7 bits of c to 0, so that the converted value represents a character in the ASCII character set. If c already represents an ASCII character, c is unchanged.
The tolower routine converts c to lowercase if c represents an uppercase letter. Otherwise, c is unchanged.
The _tolower routine is a version of tolower to be used only when c is known to be uppercase. The result of _tolower is undefined if c is not an uppercase letter.
The toupper routine convers c to uppercase if c represents an lowercase letter. Otherwise, c is unchanged.
The _toupper routine is a version of toupper to be used only when c is known to be lowercase. The result of _toupper is undefined if c is not a lowercase letter.
These routines are implemented both as functions and as macros. To conform to the ANSI specification, the tolower and toupper routines are also implemented as functions. The function versions can be used by removing the macro definitions through #undef directives or by not including CTYPE.H. Function declarations of tolower and toupper are given in STDLIB.H.
If the /Za compile option is used, the macro form of toupper or tolower is not used because it evaluates its argument more than once. Since the arguments are evaluated more than once, arguments with side effects would produce potentially bad results.
The __toascii, tolower, _tolower, toupper, and _toupper routines return the converted character c. There is no error return.
__toascii, _tolower, _toupper
Standards:UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
Use __toascii for compatibility with ANSI naming conventions of non-ANSI functions. Use toascii and link with OLDNAMES.LIB for UNIX compatibility.
tolower, toupper
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
is functions
/* TOUPPER.C: This program uses toupper and tolower to analyze all
* characters between 0x0 and 0x7F. It also applies _toupper and _tolower
* to any code in this range for which these functions make sense.
*/
#include <conio.h>
#include <ctype.h>
#include <string.h>
char msg[] = "Some of THESE letters are Capitals\r\n";
char *p;
void main( void )
{
_cputs( msg );
/* Reverse case of message. */
for( p = msg; p < msg + strlen( msg ); p++ )
{
if( islower( *p ) )
_putch( _toupper( *p ) );
else if( isupper( *p ) )
_putch( _tolower( *p ) );
else
_putch( *p );
}
}
Some of THESE letters are Capitals
sOME OF these LETTERS ARE cAPITALS