The goal of this tutorial is to closely investigate the isupper function in the C programming language. This tutorial is divided into four relevant parts:
Return: non-zero value if int c is an uppercase alphabetic value. Otherwise, 0.
Parameter list: (int c) - the character that is checked to determine the return value.
Header file:<ctype.h>.
1. So, what is the isupper function in C?
This function checks if the passed char
value is an uppercase alphabetic value or not, and returns an appropriate value of type int
indicating the result.
If the argument is an uppercase alphabetic value, the isupper function returns a non-zero value.
If the argument is not a uppercase alphabetic value, the isupper function returns a zero.
Function isupper is defined in <ctype.h> library. To use this function, we need to include <ctype.h> header file into our C program (e.g. #include <ctype.h>).
Example 1: Usage of the isupper function in C.
#include<ctype.h>
#include<stdio.h>
intmain(void)
{
printf("1. %d\n",isupper('a'));
printf("2. %d",isupper('A'));
return(0);
}
Possible output:
1. 0
2. 1
2. How to rewrite the isupper function in C?
Consider the code example below for a moment:
Example 2: rewritten isupper function in C.
intour_isupper(intc)
{
if( c>=65&&c<=90 )
return(1);
return(0);
}
The our_isupper function above takes in one parameter. Since this
parameter c is of int
type, arguments of char type (when sent as arguments to this
function) get implicitly typecasted to an according ASCII value.
Then it is checked if the received value of c is in the range of [65,90] (On line 3). If this condition is true, it means that the value is in the uppercase alphabet and 1 is returned. Otherwise 0 is returned, which is indicative that the value c is not in the uppercase alphabet.
3. Testing the rewritten isupper function
In the code example below, we have set up a simple test that checks if our_isupper function returns the same values as the isupper function from the standard C library.
Example 3: Test of the rewritten isupper function in C.