Chapter Contents |
Previous |
Next |
isascii |
Portability: | SAS/C extension |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTIONS | |
PORTABILITY | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <lctype.h> int isascii(int c);
DESCRIPTION |
isascii
tests an integer value
c
to determine whether
it is the EBCDIC equivalent of a character belonging to the ASCII character
set.
RETURN VALUE |
isascii
returns 0 if the character is not ASCII, or a nonzero value if it is ASCII.
If the argument does not have a
char
value,
0 is returned.
CAUTIONS |
Do not assume that
isascii
returns either 0 or 1.
PORTABILITY |
You should carefully examine the use of
isascii
in a program that you expect to be portable.
Traditionally,
isascii
is used to determine
whether an integer is a valid character. Unfortunately, in an EBCDIC environment,
the name and the function do not mesh well. This implementation defines the
isebcdic
function to test for validity as a
char
value and defines
isascii
as stated above. Therefore, many programs that use
isascii
should be
changed to use
isebcdic
when running on the mainframe, unless the intent is to test for membership
in the ASCII character set without regard to the native character set of the
hardware on which the program is executed.
IMPLEMENTATION |
isascii
is implemented by a true function.
isascii
tests a character to see whether it is the EBCDIC equivalent of a character
in the ASCII character set. This does not produce the same value as the following
statement:
((unsigned) c) <128
This statement frequently implements
isascii
in a C implementation that uses ASCII as its native character
set.
Also note that
isascii('\n')
has the value 0.
EXAMPLE |
This example tests for printable ASCII characters:
#include <lctype.h> #include <stdio.h> main() { char input; puts("Enter a character: "); input = getc(); if (isascii(input) && !iscntrl(input)){ puts(" The character you typed is standard ASCII, "); puts(" and it is not a control character."); } else if(!isascii(input) || iscntrl(input){ puts(" The character you typed is not a standard ASCII"); puts(" character, or it is a control character."); } }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.