C library function - isalpha()



Description

The C library function int isalpha(int c) checks if the passed character is alphabetic.

Declaration

Following is the declaration for isalpha() function.

int isalpha(int c);

Parameters

  • c − This is the character to be checked.

Return Value

This function returns non-zero value if c is an alphabet, else it returns 0.

Example

The following example shows the usage of isalpha() function.

#include <stdio.h>
#include <ctype.h>

int main () {
   int var1 = 'd';
   int var2 = '2';
   int var3 = '\t';
   int var4 = ' ';
    
   if( isalpha(var1) ) {
      printf("var1 = |%c| is an alphabet\n", var1 );
   } else {
      printf("var1 = |%c| is not an alphabet\n", var1 );
   }
   
   if( isalpha(var2) ) {
      printf("var2 = |%c| is an alphabet\n", var2 );
   } else {
      printf("var2 = |%c| is not an alphabet\n", var2 );
   }
   
   if( isalpha(var3) ) {
      printf("var3 = |%c| is an alphabet\n", var3 );
   } else {
      printf("var3 = |%c| is not an alphabet\n", var3 );
   }
   
   if( isalpha(var4) ) {
      printf("var4 = |%c| is an alphabet\n", var4 );
   } else {
      printf("var4 = |%c| is not an alphabet\n", var4 );
   }
   
   return(0);
}

Let us compile and run the above program, to produce the following result −

var1 = |d| is an alphabet                                                   
var2 = |2| is not an alphabet                                               
var3 = |        | is not an alphabet                                        
var4 = | | is not an alphabet  
ctype_h.htm
Advertisements