C Data Type Functions - C toupper






Converts a lowercase character to uppercase.

Prototype

int toupper ( int c );

Parameter

This function has the following parameter.

c
Character to be converted, casted to an int, or EOF.

Return

The uppercase equivalent to c, if such value exists, or c (unchanged) otherwise.

The value is returned as an int value that can be implicitly casted to char.

Example


#include <stdio.h>
#include <ctype.h>
//from   w w  w. jav a  2s .c  om
int main (){
  int i=0;
  char str[]="Test String.\n";
  char c;
  while (str[i])
  {
    c=str[i];
    putchar (toupper(c));
    i++;
  }
  return 0;
} 

       

The code above generates the following result.





Example 2


#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>
 /*from  w w w  .j a v  a 2 s .c o  m*/
int main(void)
{
    unsigned char u;
    for (unsigned char l=0; l<UCHAR_MAX; l++) {
        u = toupper(l);
        if (l!=u) printf("%c%c ", l,u);
    }
    printf("\n\n");
 
    unsigned char c = '\xb8'; // the character ? in ISO-8859-15
                              // but ? (acute accent) in ISO-8859-1 
    unsigned char c2 = c;   // for printing
    setlocale(LC_ALL, "en_US.iso88591");
    printf("in iso8859-1, toupper('0x%x') gives 0x%x\n", c2, toupper(c));
    setlocale(LC_ALL, "en_US.iso885915");
    printf("in iso8859-15, toupper('0x%x') gives 0x%x\n", c2, toupper(c));
}

The code above generates the following result.