Skip to content
Related Articles

Related Articles

Improve Article

toupper() function in C

  • Difficulty Level : Basic
  • Last Updated : 04 Aug, 2021

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:- 

c




// 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;
}
Output: 
g in uppercase is represented as  G

 

Example 2:- 



C




// 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;
}
Output: 
GEEKFORGEEKS

 

Note:  

 If the character passed in the toupper() is any of these three

1. uppercase character

2. special symbol

3. digit

toupper() will return the character as it is.
                      

Example :

C




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

Output:

GEEKS@123

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.



My Personal Notes arrow_drop_up
Recommended Articles
Page :