toupper in c

If you want to convert toupper in c then read this blogpost.

What is toupper in c?

toupper is a c library function which converts lowercase letters to uppercase letters.

This function is defined in ctype.h header file.

This function returns converted uppercase letters as int value which is converted to char.

Prototype

#include<ctype.h>
int toupper(int x);

Parameters of toupper in c

toupper function takes a characters as parameter.

Return value of toupper in c

This function returns converted uppercase letters as int then casted to char if it exists otherwise value is unchanged.


Example program for toupper in c

Example 1

#include<stdio.h>
#include<ctype.h>
int main()
{
  int i=0;
  char string[30]="scholarsoul";
  while(string[i])
  {
   string[i]=toupper(string[i]);
   i++;
  }
  printf("The result is %s \n",string);
  return 0;
} 
Example for toupper in c programming
Example for toupper in c programming

Code explanation

The input string is passed to the toupper function to convert it from lowercase letters to uppercase letters. The result is being printed onto the console.


Example 2

#include<stdio.h>
#include<ctype.h>
int main()
{
  int i=0;
  char string[30];
  printf("\n\n\tEnter the input in lowercase \n\t");
  scanf("%s",string);
  while(string[i])
  {
   string[i]=toupper(string[i]);
   i++;
  }
  printf("\n\tThe result is %s \n\n",string);
  return 0;
}
Example for toupper in c programming 2
Example for toupper in c programming 2

Code explanation

The input is taken from the user and passed to the toupper function. It converts the given string to uppercase letters and the result is being printed onto the console.

toupper() Man page


Difference between toupper and tolower in c

toupper is a c library function that converts lowercase letters to uppercase letters. tolower is a c library function that converts given uppercase letters to lowercase letters.

toupper function returns converted uppercase letters as an integer which is then cast to char. tolower function returns converted lowercase letters as an integer which is then cast to char.

Prototypes are as follows

int toupper(int y);

int tolower(int x);
toupper in ctolower in c
Converts lowercase letters to uppercase letters.Converts given uppercase letter to lowercase.
int toupper(int y);int tolower(int x);

Difference between toupper and isupper in c

toupper is a c library function that converts lowercase letters to uppercase letters. isupper function checks whether a character is in uppercase or not.

toupper function returns converted uppercase letters as an integer which is then cast to char. isupper function returns non-zero number if a given character is in uppercase otherwise zero.

Prototypes are as follows

int toupper(int y);

int isupper(int x);
toupper in cisupper in c
Converts lowercase letters to uppercase letters.Checks whether a character is in uppercase or not.
int toupper(int y);int isupper(int x);

People also ask for

Which header file must be included to use function toupper in c?

ctype.h header file must be included to work toupper function in c. toupper function converts lowercase letters to uppercase letters.

Which type of input is accepted in toupper function in c?

char type of input is accepted by toupper function in c. It converts lowercase letters to uppercase letters.