isalnum() to isxdigit() — Test integer value

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3

both  

Format

#include <ctype.h>

int isalnum(int c);
int isalpha(int c);
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);

General description

The functions listed above, which are all declared in ctype.h, test a given integer value. The valid integer values for c are those representable as an unsigned char or EOF.

By default, the functions are defined as macros when ctype.h is included. For better performance, the macro forms are recommended over the functional forms.

However, to get the functional forms, do one or more of the following:
  • For C only: do not include ctype.h.
  • Specify #undef, for example, #undef islower
  • Surround the call statement by parentheses, for example, (islower)('a')
Here are descriptions of each function in this group.
isalnum()
Test for an upper- or lowercase letter, or a decimal digit, as defined in the alnum locale source file and in the alnum class of the LC_CTYPE category of the current locale.
isalpha()
Test for an alphabetic character, as defined in the alpha locale source file and in the alpha class of the LC_CTYPE category of the current locale.
iscntrl()
Test for any control character, as defined in the cntrl locale source file and in the cntrl class of the LC_CTYPE category of the current locale.
isdigit()
Test for a decimal digit, as defined in the digit locale source file and in the digit class of the LC_CTYPE category of the current locale.
isgraph()
Test for a printable character excluding space, as defined in the graph locale source file and in the graph class of the LC_CTYPE category of the current locale.
islower()
Test for a lowercase character, as defined in the lower locale source file and in the lower class of the LC_CTYPE category of the current locale.
isprint()
Test for a printable character including space, as defined in the print locale source file and in the print class of the LC_CTYPE category of the current locale.
ispunct()
Test for any nonalphanumeric printable character, excluding space, as defined in the punct locale source file and in the punct class of the LC_CTYPE category of the current locale.
isspace()
Test for a white space character, as defined in the space locale source file and in the space class of the LC_CTYPE category of the current locale.
isupper()
Test for an uppercase character, as defined in the upper locale source file and in the upper class of the LC_CTYPE category of the current locale.
isxdigit()
Test for a hexadecimal digit, as defined in the xdigit locale source file and in the xdigit class of the LC_CTYPE category of the current locale.

The space, uppercase, and lowercase characters can be redefined by their respective class of the LC_CTYPE in the current locale. The LC_CTYPE category is discussed in the “Internationalization: Locales and Character Sets” in z/OS XL C/C++ Programming Guide.

Returned value

If the integer satisfies the test condition, these functions return nonzero.

If the integer does not satisfy the test condition, these functions return 0.

Example

CELEBI02
⁄* CELEBI02                                      

   This example analyzes all characters between code 0x0 and                    
   code UPPER_LIMIT.                                                            
   The output of this example is a 256-line table showing the                   
   characters from 0 to 255, and a notification of whether they                 
   have the attributes tested.                                                  
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <ctype.h>                                                              
                                                                                
#define UPPER_LIMIT   0xFF                                                      
                                                                                
int main(void)                                                                  
{                                                                               
   int ch;                                                                      
                                                                                
   for ( ch = 0; ch <= UPPER_LIMIT; ++ch )                                      
   {                                                                            
      printf("%3d ", ch);                                                       
      printf("%#04x ", ch);                                                     
      printf(" %c",  isprint(ch)  ? ch   : ' ');                                
      printf("%3s ", isalnum(ch)  ? "Alphanumeric" : " ");                      
      printf("%2s ", isalpha(ch)  ? "Alphabetic"  : " ");                       
      printf("%2s",  iscntrl(ch)  ? "Control"  : " ");                          
      printf("%2s",  isdigit(ch)  ? "Digit"  : " ");                            
      printf("%2s",  isgraph(ch)  ? "Graphic"  : " ");                          
      printf("%2s ",  islower(ch)  ? "Lower"  : " ");                           
      printf("%3s",  ispunct(ch)  ? "Punctuation" : " ");                       
      printf("%2s",  isspace(ch)  ? "Space"  : " ");                            
      printf("%3s",  isprint(ch)  ? "Printable" : " ");                         
      printf("%2s ",  isupper(ch)  ? "Upper"  : " ");                           
      printf("%2s ",  isxdigit(ch) ? "Hex"  : " ");                             
                                                                                
      putchar('\n');                                                            
   }                                                                            
}                                                                               

Related information