C Standard Library

C <ctype.h> - toupper() Function



The C <ctype.h> toupper() function is used to convert the given character to uppercase according to the character conversion rules defined by the currently installed C locale.

In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ.

Syntax

int toupper ( int ch );               

Parameters

ch Specify the character to be converted, casted to an int, or EOF.

Return Value

Returns uppercase version of ch or unchanged ch if no uppercase value is listed in the current C locale.

Example:

The example below shows the usage of toupper() function.

#include <stdio.h>
#include <ctype.h>
 
int main (){
  char str[50] = "HELLO World!";

  //converting str into upper case
  int i = 0;
  while(str[i]) {
    str[i] = toupper(str[i]);
    i++;
  }

  //displaying the output
  printf("%s\n", str);   
  return 0;
}

The output of the above code will be:

HELLO WORLD!

❮ C <ctype.h> Library