C toupper()

The toupper() function defined in the ctype.h header file. It helps to convert the given lowercase character into an uppercase character.


int toupper(int argument); #where argument will be a character
 

toupper() Parameters:

The toupper() function takes a single parameter and is in the form of an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.

Parameter Description Required / Optional
argument  The character needs to be converted Required

toupper() Return Value

This function converts the given lowercase character to an uppercase character. The value is returned as an int value that can be implicitly cast to char. If the passed argument is not a lowercase letter it will return the same passed character.

Input Return Value
lowercase character corresponding uppercase character
uppercase character or a non-alphabetic character the character itself

Examples of toupper()

Example 1: Working of toupper() function in C


#include <stdio.h>
#include <ctype.h>
int main()
{
    char ch, output;

    ch = 'A';
    output = toupper(ch);
    printf("toupper(%c) = %c\n", ch, output);

    ch = 'a';
    output = toupper(ch);
    printf("toupper(%c) = %c\n", ch, output);

    ch = '+';
    output = toupper(ch);
    printf("toupper(%c) = %c\n", ch, output);

    return 0;
}

Output:


toupper(A) = A
toupper(a) = A
toupper(+) = +

Example 2: How toupper() function works in C?


#include <stdio.h>
#include <ctype.h>
int main () {
   int k = 0;
   char ch;
   char st[] = "programming";
 
   while( st[k]) {
      putchar(toupper(st[k]));
      k++;
   }
   
   return(0);
}

Output:


PROGRAMMING