Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
ctype.h File Reference

Standard C Libraries -. More...

Go to the source code of this file.

Functions

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)
 
int tolower (int c)
 
int toupper (int c)
 

Detailed Description

Standard C Libraries -.

Compiler:
MPLAB XC16 compiler

Description

The header file, ctype.h, consists of functions that are useful for classifying and mapping characters. Characters are interpreted according to the Standard C locale.

Software License Agreement

The documentation in this header file has been copied from the documentation provided with the Microchip MPLAB XC16 compiler. The original license agreement included with the XC16 compiler applies!

Function Documentation

int isalnum ( int  c)

Description: Test for an alphanumeric character.

Include: <ctype.h>

Parameters
cThe character to test.
Returns
Returns a non-zero integer value if the character is alphanumeric; otherwise, returns a zero.

Remarks:
Alphanumeric characters are included within the ranges A-Z, a-z or 0-9.

Example:

#include <ctype.h> // for isalnum
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '3';
if (isalnum(ch))
printf("3 is an alphanumeric\n");
else
printf("3 is NOT an alphanumeric\n");
ch = '#';
if (isalnum(ch))
printf("# is an alphanumeric\n");
else
printf("# is NOT an alphanumeric\n");
}

Output:
3 is an alphanumeric
# is NOT an alphanumeric

int isalpha ( int  c)

Description: Test for an alphabetic character.

Include: <ctype.h>

Parameters
cThe character to test.
Returns
Returns a non-zero integer value if the character is alphabetic; otherwise, returns zero.

Remarks:
Alphabetic characters are included within the ranges A-Z or a-z.

Example:

#include <ctype.h> // for isalpha
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'B';
if (isalpha(ch))
printf("B is alphabetic\n");
else
printf("B is NOT alphabetic\n");
ch = '#';
if (isalpha(ch))
printf("# is alphabetic\n");
else
printf("# is NOT alphabetic\n");
}

Output:
B is alphabetic
# is NOT alphabetic

int iscntrl ( int  c)

Description: Test for a control character.

Include: <ctype.h>

Parameters
ccharacter to test.
Returns
Returns a non-zero integer value if the character is a control character; otherwise, returns zero.

Remarks:
A character is considered to be a control character if its ASCII value is in the range, 0x00 to 0x1F inclusive, or 0x7F.

Example:

#include <ctype.h> // for iscntrl
#include <stdio.h> // for printf
int main(void) {
char ch;
ch = 'B';
if (iscntrl(ch))
printf("B is a control character\n");
else
printf("B is NOT a control character\n");
ch = '\t';
if (iscntrl(ch))
printf("A tab is a control character\n");
else
printf("A tab is NOT a control character\n");
}

Output:
B is NOT a control character
A tab is a control character

int isdigit ( int  c)

Description: Test for a decimal digit.

Include: <ctype.h>

Parameters
ccharacter to test.
Returns
Returns a non-zero integer value if the character is a digit; otherwise, returns zero.

Remarks:
A character is considered to be a digit character if it is in the range of ‘0'- ‘9'.

Example:

#include <ctype.h> // for isdigit
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '3';
if (isdigit(ch))
printf("3 is a digit\n");
else
printf("3 is NOT a digit\n");
ch = '#';
if (isdigit(ch))
printf("# is a digit\n");
else
printf("# is NOT a digit\n");
}

Output:
3 is a digit
# is NOT a digit

int isgraph ( int  c)

Description: Test for a graphical character.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is a graphical character; otherwise, returns zero.

Remarks:
A character is considered to be a graphical character if it is any printable character except a space.

Example:

#include <ctype.h> // for isgraph
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '3';
if (isgraph(ch))
printf("3 is a graphical character\n");
else
printf("3 is NOT a graphical character\n");
ch = '#';
if (isgraph(ch))
printf("# is a graphical character\n");
else
printf("# is NOT a graphical character\n");
ch = ' ';
if (isgraph(ch))
printf("a space is a graphical character\n");
else
printf("a space is NOT a graphical character\n");
}

Output:
3 is a graphical character
# is a graphical character
a space is NOT a graphical character

int islower ( int  c)

Description: Test for a lower case alphabetic character.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is a lower case alphabetic character; otherwise, returns zero.

Remarks:
A character is considered to be a lower case alphabetic character if it is in the range of ‘a'-‘z'.

Example:

#include <ctype.h> // for islower
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'B';
if (islower(ch))
printf("B is lower case\n");
else
printf("B is NOT lower case\n");
ch = 'b';
if (islower(ch))
printf("b is lower case\n");
else
printf("b is NOT lower case\n");
}

Output:
B is NOT lower case
b is lower case

int isprint ( int  c)

Description: Test for a printable character (includes a space).

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is printable; otherwise, returns zero.

Remarks:
A character is considered to be a printable character if it is in the range, 0x20 to 0x7e inclusive.

Example:

#include <ctype.h> // for isprint
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '&';
if (isprint(ch))
printf("& is a printable character\n");
else
printf("& is NOT a printable character\n");
ch = '\t';
if (isprint(ch))
printf("a tab is a printable character\n");
else
printf("a tab is NOT a printable character\n");
}

Output:
& is a printable character
a tab is NOT a printable character

int ispunct ( int  c)

Description: Test for a punctuation character.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is a punctuation character; otherwise, returns zero.

Remarks:
A character is considered to be a punctuation character if it is a printable character which is neither a space nor an alphanumeric character. Punctuation characters consist of the following:

! " # $ % & ' ( ) ; < = > ? @ [ \ ] * + , - . / : ^ _ { | } ~

Example:

#include <ctype.h> // for ispunct
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '&';
if (ispunct(ch))
printf("& is a punctuation character\n");
else
printf("& is NOT a punctuation character\n");
ch = '\t';
if (ispunct(ch))
printf("a tab is a punctuation character\n");
else
printf("a tab is NOT a punctuation character\n");
}

Output:
& is a punctuation character
a tab is NOT a punctuation character

int isspace ( int  c)

Description: Test for a white-space character.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is a white-space character; otherwise, returns zero.

Remarks:
A character is considered to be a white-space character if it is one of the following:

space (' '), form feed ('\f'), newline ('\n'), carriage return('\r'), horizontal tab ('\t'), or vertical tab ('\v')

Example:

#include <ctype.h> // for isspace
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = '&';
if (isspace(ch))
printf("& is a white-space character\n");
else
printf("& is NOT a white-space character\n");
ch = '\t';
if (isspace(ch))
printf("a tab is a white-space character\n");
else
printf("a tab is NOT a white-space character\n");
}

Output:
& is NOT a white-space character
a tab is a white-space character

int isupper ( int  c)

Description: Test for an upper case letter.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is an upper case alphabetic character; otherwise, returns zero.

Remarks:
A character is considered to be an upper case alphabetic character if it is in the range of ‘A'-‘Z'.

Example:

#include <ctype.h> // for isupper
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'B';
if (isupper(ch))
printf("B is upper case\n");
else
printf("B is NOT upper case\n");
ch = 'b';
if (isupper(ch))
printf("b is upper case\n");
else
printf("b is NOT upper case\n");
}

Output:
B is upper case
b is NOT upper case

int isxdigit ( int  c)

Description: Test for a hexadecimal digit.

Include: <ctype.h>

Parameters
ccharacter to test
Returns
Returns a non-zero integer value if the character is a hexadecimal digit; otherwise, returns zero.

Remarks:
A character is considered to be a hexadecimal digit character if it is in the range of ‘0'-‘9', ‘A'-‘F', or ‘a'-‘f'. Note: The list does not include the leading 0x because 0x is the prefix for a hexadecimal number but is not an actual hexadecimal digit.

Example:

#include <ctype.h> // for isxdigit
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'B';
if (isxdigit(ch))
printf("B is a hexadecimal digit\n");
else
printf("B is NOT a hexadecimal digit\n");
ch = 't';
if (isxdigit(ch))
printf("t is a hexadecimal digit\n");
else
printf("t is NOT a hexadecimal digit\n");
}

Output:
B is a hexadecimal digit
t is NOT a hexadecimal digit

int tolower ( int  c)

Description: Convert a character to a lower case alphabetical character.

Include: <ctype.h>

Parameters
cThe character to convert to lower case.
Returns
Returns the corresponding lower case alphabetical character if the argument was originally upper case; otherwise, returns the original character.

Remarks:
Only upper case alphabetical characters may be converted to lower case.

Example:

#include <ctype.h> // for tolower
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'B';
printf("B changes to lower case %c\n",
tolower(ch));
ch = 'b';
printf("b remains lower case %c\n",
tolower(ch));
ch = '@';
printf("@ has no lower case, ");
printf("so %c is returned\n", tolower(ch));
}

Output:
B changes to lower case b
b remains lower case b
@ has no lower case, so @ is returned

int toupper ( int  c)

Description: Convert a character to an upper case alphabetical character.

Include: <ctype.h>

Parameters
cThe character to convert to upper case.
Returns
Returns the corresponding upper case alphabetical character if the argument was originally lower case; otherwise, returns the original character.

Remarks:
Only lower case alphabetical characters may be converted to upper case.

Example:

#include <ctype.h> // for toupper
#include <stdio.h> // for printf
int main(void) {
int ch;
ch = 'b';
printf("b changes to upper case %c\n",
toupper(ch));
ch = 'B';
printf("B remains upper case %c\n",
toupper(ch));
ch = '@';
printf("@ has no upper case, ");
printf("so %c is returned\n", toupper(ch));
}

Output:
b changes to upper case B
B remains upper case B
@ has no upper case, so @ is returned