toupper() function in C

The toupper() function is used to convert lowercase alphabet to uppercase. i.e. If the character passed is a lowercase alphabet then the toupper() function converts a lowercase alphabet to an uppercase alphabet. It is defined in the ctype.h header file.

Syntax:

int toupper(int ch);

Parameter: It accepts a single parameter:

  • ch: This represents the character to be converted to uppercase.

Returns: This function returns the uppercase character corresponding to the ch.

Below programs illustrate the toupper() function in C:



Example 1:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to demonstrate
// example of toupper() function.
#include <ctype.h>
#include <stdio.h>
  
int main()
{
    char ch;
  
    ch = 'g';
    printf("%c in uppercase is represented as  %c",
           ch, toupper(ch));
  
    return 0;
}

chevron_right


Output:

g in uppercase is represented as  G

Example 2:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to demonstrate
// example of toupper() function.
#include <ctype.h>
#include <stdio.h>
  
int main()
{
    int j = 0;
    char str[] = "geekforgeeks\n";
    char ch;
  
    while (str[j]) {
        ch = str[j];
        putchar(toupper(ch));
        j++;
    }
  
    return 0;
}

chevron_right


Output:

GEEKFORGEEKS

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :
    Practice Tags :


    2


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.