C Data Type Functions - C isalpha






Checks whether c is an alphabetic letter. Notice that what is considered a letter depends on the locale being used.

Prototype

int isalpha ( int c );

Parameter

This function has the following parameter.

c
Character to be checked, casted to an int, or EOF.

Return

A value different from zero (i.e., true) if indeed c is an alphabetic letter. Zero (i.e., false) otherwise.

Example


#include <stdio.h>
#include <ctype.h>
int main (){//from   w w w  .j av a 2s . c om
  int i=0;
  char str[]="C++";
  while (str[i]) {
    if (isalpha(str[i])) 
       printf ("character %c is alphabetic\n",str[i]);
    else 
       printf ("character %c is not alphabetic\n",str[i]);
    i++;
  }
  return 0;
}        

The code above generates the following result.





Example 2


#include <ctype.h>
#include <stdio.h>
#include <locale.h>
 //  w  w  w .j av a 2s. c om
int main(void){
    unsigned char c = '\xdf'; // German letter ? in ISO-8859-1
 
    printf("isalpha('\\xdf') in default C locale returned %d\n", !!isalpha(c));
 
    setlocale(LC_CTYPE, "de_DE.iso88591");
    printf("isalpha('\\xdf') in ISO-8859-1 locale returned %d\n", !!isalpha(c));
}

The code above generates the following result.