beautypg.com

Character handling

Page 441

background image

UM013037-1212

Character Handling

Zilog Developer Studio II – Z8 Encore!

User Manual

417

macro puts diagnostics into programs. When it is executed, if

expression

is false (that

is, evaluates to zero), the

assert

macro writes information about the particular call that

failed (including the text of the argument, the name of the source file, and the source line
number – the latter are respectively the values of the preprocessing macros

__FILE__

and

__LINE__

) on the serial port. It then calls

abort()

, which calls

exit()

. If

expression

is true (that is, evaluates to nonzero), the

assert

macro returns no value.

On Release builds (strictly speaking, when

NDEBUG

is defined on the compile line), the

assert

macro has no effect.

Example

#include

char str[] = "COMPASS";

int main(void)

{

assert(str[0] == 'C'); // OK, nothing happens

assert(str[0] == 'B'); // Oops, something wrong here

return 0;

}

Character Handling

The <

ctype.h

> header declares several macros and functions useful for testing and map-

ping characters. In all cases, the argument is an

int

, the value of which is represented as

an

unsigned char

or equals the value of the EOF macro. If the argument has any other

value, the behavior is undefined.

Macros

Functions

The functions in this section return nonzero (true) if, and only if, the value of the argument
c conforms to that in the description of the function. The term printing character refers to
a member of a set of characters, each of which occupies one printing position on a display
device. The term control character refers to a member of a set of characters that are not
printing characters.

Character Testing

TRUE

Expands to a constant 1.

FALSE

Expands to a constant 0.

int isalnum(int c);

Tests for alphanumeric character.

int isalpha(int c);

Tests for alphabetic character.