Presentation is loading. Please wait.

Presentation is loading. Please wait.

This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.

Similar presentations


Presentation on theme: "This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed."— Presentation transcript:

1 This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.

2 ctype.h Christine S. Wolfe Ohio University Lancaster 2008-Aug-01 This lesson introduces the library functions included in ctype.h: Vocabulary: ctype.h isalnum() isalpha() iscntrl() isdigit() isgraph() islower() isprint() ispunct() isspace() isupper() isxdigit() tolower() toupper()

3 C Primer Plus®, Third Edition by Stephen Prata. Publisher: Sams Pub Date: September 28, 1998 Print ISBN-10: 1-57169-161-8 Table 7.1. ctype.h character-testing functions. NameTrue If Argument Is isalnum()Alphanumeric (alphabetic or numeric) isalpha()Alphabetic iscntrl()A control character, such as Ctrl+B isdigit()A digit isgraph()Any printing character other than a space islower()A lowercase character isprint()A printing character ispunct()A punctuation character (any printing character other than a space or an alphanumeric character) isspace()A whitespace character: space, newline, formfeed, carriage return, vertical tab, horizontal tab, or, possibly, other implementation-defined characters isupper()An uppercase character isxdigit()A hexadecimal-digit character Table 7.2. ctype.h character-mapping functions. NameAction tolower()If the argument is an uppercase character, returns the lowercase version; otherwise, just returns the original argument toupper()If the argument is a lowercase character, returns the uppercase version; otherwise, just returns the original argument The ctype.h header file includes several useful functions. The argument for these functions is a single char.

4 Before these functions can be used in a program, the ctype.h library must be included. #include int main() { char Response; printf("Please enter your selection: "); fflush(stdin); scanf("\n%c", &Response); if ( toupper(Response) == 'Q') { return 0; } }

5 isalnum() isalpha() iscntrl() isdigit() isgraph() islower() isprint() ispunct() isspace() isupper() isxdigit() The ctype functions that begin with "is" are boolean. That means they return either TRUE or FALSE, the logical values.

6 Given that the user entered 'A' as Response, what is the value of each of these expressions? isalnum(Response) isalpha(Response) iscntrl(Response) isdigit(Response) isgraph(Response) islower(Response) isprint(Response) ispunct(Response) isspace(Response) isupper(Response) isxdigit(Response) Click for answer True False True False True False True Click for answer

7 Given that the user entered '6' as Response, what is the value of each of these expressions? isalnum(Response) isalpha(Response) iscntrl(Response) isdigit(Response) isgraph(Response) islower(Response) isprint(Response) ispunct(Response) isspace(Response) isupper(Response) isxdigit(Response) Click for answer True False True False True False True Click for answer

8 tolower() toupper() The ctype functions that begin with "to" return a char value. They do NOT change the value of the argument itself. For example: Letter1 = toupper(Letter2); BEFOREAFTER Letter1Letter2Letter1Letter2 hHh GGG 666 ;;;

9 The argument for the ctype.h library functions MUST BE A char!!! Given the declarations below, the following statements are syntactically incorrect: int NumIn = 345; char Name[20] = "hal"; char Proper[20]; if (isDigit(NumIn)) Proper = toupper(Name); Please don't look at this slide for too long - I don't to plant these ideas in your head if they weren't already there!!!


Download ppt "This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed."

Similar presentations


Ads by Google