Presentation is loading. Please wait.

Presentation is loading. Please wait.

CTYPE.H www.ustudy.in. Introduction  The ctype header is used for testing and converting characters.  A control character refers to a character that.

Similar presentations


Presentation on theme: "CTYPE.H www.ustudy.in. Introduction  The ctype header is used for testing and converting characters.  A control character refers to a character that."— Presentation transcript:

1 CTYPE.H www.ustudy.in

2 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

3 NAME ctype.h - character types SYNOPSIS #include 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

4 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

5 Example #include //isalnum() #include //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

6 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

7 Example #include //isalpha() #include //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

8 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

9 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

10 isdigit NAME isdigit - test for a decimal digit SYNOPSIS #include 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

11 Example #include //isdigit() #include //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

12 isxdigit NAME isxdigit - test for a hexadecimal digit SYNOPSIS #include 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

13 Example #include //isxdigit() #include //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

14 isgraph NAME isgraph - test for a visible character SYNOPSIS #include 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

15 islower NAME islower - test for a lower-case letter SYNOPSIS #include 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

16 Example #include //islower() #include //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

17 isupper NAME isupper - test for an upper-case letter SYNOPSIS #include 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

18 Example #include //isupper() #include //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

19 isprint NAME isprint - test for a printing character SYNOPSIS #include 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

20 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.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

21 isspace NAME isspace - test for a white-space character SYNOPSIS #include 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

22 toascii NAME toascii - translate integer to a 7-bit ASCII character SYNOPSIS #include 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

23 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

24 Example #include 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

25 toupper NAME toupper - transliterate lower-case characters to upper-case SYNOPSIS #include 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

26 Example #include 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

27 The End Thank U www.ustudy.in


Download ppt "CTYPE.H www.ustudy.in. Introduction  The ctype header is used for testing and converting characters.  A control character refers to a character that."

Similar presentations


Ads by Google