Format
#include <ctype.h> int isascii(int c);
Language Level: XPG4
Threadsafe: Yes.
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
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.