tolower(), toupper() — Convert character case

Standards

Standards / Extensions C or C++ Dependencies
ISO C
POSIX.1
XPG4
XPG4.2 C99 Single UNIX Specification, Version 3
both  

Format

#include <ctype.h>

int tolower(int c);   /* Convert c to lowercase if appropriate */
int toupper(int c);   /* Convert c to uppercase if appropriate */

General description

Converts c to a lowercase letter, if possible. Conversely, the toupper() function converts c to an uppercase letter, if possible.

The DBCS is not supported. The use of characters from the DBCS results in unspecified behavior.

Returned value

If successful, tolower() and toupper() return the corresponding character, as defined in the LC_CTYPE category of the current locale, if such a character exists.

If unsuccessful, tolower() and toupper() return the unchanged value c.

Example

CELEBT15
/* CELEBT15                                      

   This example demonstrates the result of using                                
   &toupper. and &tolower. on a lower-case a.                                   
                                                                                
 */                                                                             
#include <stdio.h>                                                              
#include <ctype.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   int ch;                                                                      
                                                                                
   ch = 0x81;                                                                   
   printf("toupper=%#04x\n", toupper(ch));                                      
   printf("tolower=%#04x\n", tolower(ch));                                      
}                                                                               

Related information