320 likes | 657 Views
CTYPE.H. Introduction. The ctype header is used for testing and converting characters. A control character refers to a character that is not part of the normal printing set.
E N D
CTYPE.H www.ustudy.in
Introduction • The ctype header is used for testing and converting characters. • A control character refers to a character that is not part of the normal printing set. • In the ASCII character set, the control characters are the characters from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL). • Printable characters are those from 0x20 (space) to 0x7E (tilde). www.ustudy.in
NAME ctype.h - character types SYNOPSIS #include <ctype.h> DESCRIPTION • The header ctype.h in the ANSI C Standard Library for the C programming language contains declarations for character classification functions. • Function prototypes must be provided for use with an ISO C compiler. www.ustudy.in
isalnum NAME isalnum - test for an alphanumeric character SYNOPSIS #include <ctype.h> int isalnum(int c); DESCRIPTION • The isalnum() function tests whether c is a character of class alpha or digit in the program's current locale, see the XBD specification, locale. • In all cases c is an int, the value of which must be representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. RETURN VALUE • The isalnum() function returns non-zero if c is an alphanumeric character; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //isalnum() #include<stdio.h> //printf() void test_isalnum() { int arr[]={'8',0xe1,'5','Z',0xfd}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = isalnum(arr[i]); //call to the API with chars in arr[] if( (!ret) != 0 ) { printf(“ c is not alphanumeric", arr[i]); } else { printf(" %c is an alphanumeric ", arr[i]); } } } Output a is an alphanumeric 5 is an alphanumeric Z is an alphanumeric www.ustudy.in
isalpha NAME isalpha - test for an alphabetic character SYNOPSIS #include <ctype.h> int isalpha(int c); DESCRIPTION • The isalpha() function tests whether c is a character of class alpha in the program's current locale, see the XBD specification,locale. • In all cases c is an int, the value of which must be representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. RETURN VALUE The isalpha() function returns non-zero if c is an alphabetic character; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //isalpha() #include<stdio.h> //printf() void test_isalpha() { int arr[]={'a',0xe1,'5','Z',0xfd}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = isalpha(arr[i]); //call to the API with chars in arr[] if( (!ret) != 0 ) { printf(“c is not an alphabet", arr[i]); } else { printf(" %c is an alphabet", arr[i]); } } } Output a is an alphabet 5 is not an alphabet Z is an alphabet www.ustudy.in
isascii NAME isascii - test for a 7-bit US-ASCII character SYNOPSIS #include <ctype.h> int isascii(int c); DESCRIPTION • The isascii() function tests whether c is a 7-bit US-ASCII character code. The isascii() function is defined on all integer values. RETURN VALUE • The isascii() function returns non-zero if c is a 7-bit US-ASCII character code between 0 and octal 0177 inclusive; otherwise it returns 0. www.ustudy.in
iscntrl NAME iscntrl - test for a control character SYNOPSIS #include <ctype.h> int iscntrl(int c); DESCRIPTION • The iscntrl() function tests whether c is a character of class cntrl in the program's current locale, see the XBD specification,locale. • In all cases c is a type int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The iscntrl() function returns non-zero if c is a control character; otherwise it returns 0. www.ustudy.in
isdigit NAME isdigit - test for a decimal digit SYNOPSIS #include <ctype.h> int isdigit(int c); DESCRIPTION • The isdigit() function tests whether c is a character of class digit in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The isdigit() function returns non-zero if c is a decimal digit; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //isdigit() #include<stdio.h> //printf() void test_isdigit() { int arr[]={'8',0xe1,'5','Z',0xfd}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = isdigit(arr[i]); //call to the API with chars in arr[] if( (!ret) != 0 ) { printf(" %c is not a digit", arr[i]); } else { printf(" %c is a digit", arr[i]); } } printf(" "); } Output 8 is a digit 5 is a digit Z is not a digit www.ustudy.in
isxdigit NAME isxdigit - test for a hexadecimal digit SYNOPSIS #include <ctype.h> int isxdigit(int c); DESCRIPTION • The isxdigit() function tests whether c is a character of class xdigit in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. RETURN VALUE • The isxdigit() function returns non-zero if c is a hexadecimal digit; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //isxdigit() #include<stdio.h> //printf() int test_isxdigit() { int arr[]={'F','a','M','9','2'}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = isxdigit(arr[i]); //call to the API with chars in arr[] if( (!ret) != 0 ) { printf(" %c is not hex-digit ", arr[i]); } else { printf(" %c is hex-digit", arr[i]); } } printf(" "); } Output • F is hex-digit a is hex-digit M is not hex-digit 9 is hex-digit www.ustudy.in
isgraph NAME isgraph - test for a visible character SYNOPSIS #include <ctype.h> int isgraph(int c); DESCRIPTION • The isgraph() function tests whether c is a character of class graph in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The isgraph() function returns non-zero if c is a character with a visible representation; otherwise it returns 0. www.ustudy.in
islower NAME islower - test for a lower-case letter SYNOPSIS #include <ctype.h> int islower(int c); DESCRIPTION • The islower() function tests whether c is a character of class lower in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The islower() function returns non-zero if c is a lower-case letter; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //islower() #include<stdio.h> //printf() int test_islower() { int arr[]={0x0126,0xee,'r','9','g'}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = islower(arr[i]); //call to the API with chars in the arr[] if( (!ret) != 0 ) { printf(" %c is not in lower-case ", arr[i]); } else { printf(" %c is in lower-case", arr[i]); } } printf(" "); } Output & is not in lower-case 9 is not in lower-case g is in lower-case www.ustudy.in
isupper NAME isupper - test for an upper-case letter SYNOPSIS #include <ctype.h> int isupper(int c); DESCRIPTION • The isupper() function tests whether c is a character of class upper in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The isupper() function returns non-zero if c is an upper-case letter; otherwise it returns 0. www.ustudy.in
Example #include<ctype.h> //isupper() #include<stdio.h> //printf() int test_isupper() { int arr[]={0x0126,'G','7','B',0x3041}; int i = 0; int size = 5; for( i=0; i<size; i++) { int ret = isupper(arr[i]); //call to the API with chars in arr[] if( (!ret) != 0 ) { printf(" %c is not in upper-case ", arr[i]); } else { printf(" %c is in upper-case", arr[i]); } } printf(" "); } Output G is in upper-case 7 is not in upper-case A is in upper-case www.ustudy.in
isprint NAME isprint - test for a printing character SYNOPSIS #include <ctype.h> int isprint(int c); DESCRIPTION • The isprint() function tests whether c is a character of class print in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The isprint() function returns non-zero if c is a printing character; otherwise it returns 0. www.ustudy.in
ispunct NAME ispunct - test for a punctuation character SYNOPSIS #include <ctype.h> int ispunct(int c); DESCRIPTION • The ispunct() function tests whether c is a character of class punct in the program's current locale, see the XBD specification, Locale. • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. RETURN VALUE • The ispunct() function returns non-zero if c is a punctuation character; otherwise it returns 0. www.ustudy.in
isspace NAME isspace - test for a white-space character SYNOPSIS • #include <ctype.h> int isspace(int c); DESCRIPTION • The isspace() function tests whether c is a character of class space in the program's current locale, see the XBD specification, Locale . • In all cases c is an int, the value of which must be a character representable as an unsigned char or must equal the value of the macro EOF. If the argument has any other value, the behaviour is undefined. RETURN VALUE • The isspace() function returns non-zero if c is a white-space character; otherwise it returns 0. www.ustudy.in
toascii NAME toascii - translate integer to a 7-bit ASCII character SYNOPSIS #include <ctype.h> int toascii(int c); DESCRIPTION • The toascii() function converts its argument into a 7-bit ASCII character. RETURN VALUE • The toascii() function returns the value (c & 0x7f). www.ustudy.in
tolower NAME tolower - transliterate upper-case characters to lower-case SYNOPSIS #include <ctype.h> int tolower(int c); DESCRIPTION • The tolower() function has as a domain a type int, the value of which is representable as an unsigned char or the value of EOF. If the argument has any other value, the behaviour is undefined. • If the argument of tolower() represents an upper-case letter, and there exists a corresponding lower-case letter (as defined by character type information in the program locale category LC_CTYPE), the result is the corresponding lower-case letter. All other arguments in the domain are returned unchanged. RETURN VALUE • On successful completion, tolower() returns the lower-case letter corresponding to the argument passed; otherwise it returns the argument unchanged. www.ustudy.in
Example #include <stdio.h> #include<ctype.h> int main() { printf( "Lower case of A is %c\n", tolower('A')); printf( "Lower case of 9 is %c\n", tolower('9')); printf( "Lower case of g is %c\n", tolower('g')); return 0; } Output: Lower case of A is a Lower case of 9 is 9 Lower case of g is g www.ustudy.in
toupper NAME toupper - transliterate lower-case characters to upper-case SYNOPSIS #include <ctype.h> int toupper(int c); DESCRIPTION • The toupper() function has as a domain a type int, the value of which is representable as an unsigned char or the value of EOF. If the argument has any other value, the behavior is undefined. • If the argument of toupper() represents a lower-case letter, and there exists a corresponding upper-case letter (as defined by character type information in the program locale category LC_CTYPE), the result is the corresponding upper-case letter. All other arguments in the domain are returned unchanged. RETURN VALUE • On successful completion, toupper() returns the upper-case letter corresponding to the argument passed. www.ustudy.in
Example #include <stdio.h> #include<ctype.h> int main() { printf( “Upper case of a is %c\n", toupper(‘a')); printf( " Upper case of 9 is %c\n", toupper('9')); printf( " Upper case of g is %c\n", toupper(‘G')); return 0; } Output: Upper case of a is A Upper case of 9 is 9 Upper case of G is G www.ustudy.in
The End Thank U www.ustudy.in