Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

toupper in C Programming

by suresh

The C toupper function is one of the Standard Library Functions available in C language, used to convert the given character into Uppercase character. The syntax of the toupper in C Programming language is

The below function accepts the single character as the parameter, and convert the given character to uppercase using the toupper in C.

toupper(char)

toupper in C Programming Example

The toupper function used to convert the given character to uppercase. This C program allows the user to enter any character, and convert that character to uppercase using the toupper function.

//Example for toupper in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
   char ch;
   printf("Please Enter Any Valid Character: \n");
   scanf("%c", &ch);

   printf("\n We Converted Your character to Upper Case = %c", toupper(ch));         

}

OUTPUT

toupper in C Programming 1

ANALYSIS

First, we declared a character variable called ch

char ch;

The following C Programming statement will ask the user to enter any character. And then, we are using the scanf to assign the user entered character to ch variable

printf("Please Enter Any Valid Character: \n");
scanf("%c", &ch);

Next, we used the toupper function directly inside the printf statements to print the output. The below statement will convert the character in ch variable to uppercase

printf("\n We Converted Your character to Upper Case = %c", toupper(ch));

The above code will definitely convert the given character to uppercase, but what if we enter the numeric value

toupper in C Programming 2

As you can see, it is not throwing any error, which might not be good at real-time.

toupper in C Programming Example 2

In this toupper example, we will show you a better approach to the program mentioned above.

//Example for toupper in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    printf("Please Enter Any Valid Character: \n");
    scanf("%c", &ch);

    if(isalpha(ch))
    {
      printf("\n We Converted Your character to Upper Case = %c", toupper(ch));         
    }
    else
    {
      printf("\n Please Enter a Valid character"); 
    }
}

OUTPUT

toupper in C Programming 3

ANALYSIS

In this toupper code snippet, we added the If Statement to check whether the character is between ‘A’ and ‘Z’ using isalpha function. If the condition is True, it will convert the given character to Uppercase using below statement

printf("\n We Converted Your character to Upper Case = %c", toupper(ch));

If the above condition is FALSE, then the given character is not Alphabet So, it will print the below statement

printf("\n Please Enter a Valid character");

Let me enter the numeric value as an input

toupper in C Programming 4

TIP: Please refer C Program to Convert Character to Uppercase article. This is useful to understand how to convert the character to lowercase without using the toupper function.

Placed Under: C Programming

  • C Comments
  • C Escape Sequence
  • C Programming Operators
  • C Arithmetic Operators
  • C Assignment Operators
  • C Bitwise Operators
  • C Conditional Operator
  • C Increment & Decrement Optr
  • C Logical Operators
  • C Relational Operators
  • C Sizeof Operator
  • C If Statement
  • C IF ELSE Statement
  • C Else If Statement
  • C Nested If
  • C Break Statement
  • C Continue Statement
  • C Goto Statement
  • C Switch Case
  • C For Loop
  • C While Loop
  • C Do While Loop
  • C Arrays
  • C Two Dimensional Array
  • C Multi Dimensional Array
  • C String
  • C Structures
  • C Nested Structures
  • C Array of Structures
  • C Structures and Functions
  • C Union
  • C Structure & Union differences
  • C Pointers
  • C Pass Pointers to Functions
  • C GETS
  • C fgets Function
  • C fgetc
  • C fputs function
  • C fputc
  • C Functions
  • C Types of Functions
  • C Pass Array to Functions
  • Call By Value & Call By Reference
  • C Recursion
  • C Program Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy