isascii() — Test for Character Representable as ASCII Value

Format

#include <ctype.h>
int isascii(int c);

Language Level: XPG4

Threadsafe: Yes.

Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE category of the current locale. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.

Description

The isascii() function tests if a given character, in the current locale, can be represented as a valid 7–bit US-ASCII character.

Return Value

The isascii() function returns nonzero if c, in the current locale, can be represented as a character in the 7–bit US-ASCII character set. Otherwise, it returns 0.

Example that uses isascii()

This example tests the integers from 0x7c to 0x82, and prints the corresponding character if the integer can be represented as a character in the 7–bit US-ASCII character set.

#include <stdio.h>
#include <ctype.h>
 
int main(void)
{
   int ch;
 
   for (ch = 0x7c; ch <= 0x82; ch++) {
      printf("%#04x    ", ch);
      if (isascii(ch))
         printf("The character is %c\n", ch);
      else
         printf("Cannot be represented by an ASCII character\n");
   }
   return 0;
}
   /************************************************
      The output should be:
 
	0x7c    The character is @
	0x7d    The character is '
	0x7e    The character is =
	0x7f    The character is "
	0x80    Cannot be represented by an ASCII character  
	0x81    The character is a
	0x82    The character is b
 
   ************************************************/
 

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]