Ch 8 Characters and Strings Timothy Budd Characters
Ch 8. Characters and Strings Timothy Budd
Characters and Literals Strings • Char in C++ is normally an 8 -bit quantity, whereas in Java it is a 16 -bit value. • Char can be declared either as signed or unsigned. • wchar_t represents a wide character, 16 -bit character. 2
Character Literals and the cctype Library isalpha(c) isupper(c) islower(c) isdigit(c) isxdigit(c) isalnum(c) isspace(c) isprint(c)} True if c is alphabetic True if c is upper case True if c is lower case True if c is decimal digit char True if c is hexidecimal digit True if c is alphabetic or numeric True if c is whitespace (space, tab or newline) True if c is a printable character (8 bit only) 3
String Literals • A literal string value has type array of character in C++, whereas it has type string in Java. • Always remember the null character at the end of a string literal. 4
char * text = "A Literal Text"; int vowel. Count (char const * p) { // procedure to count vowels in text int sum = 0; while (1) { // will break out of loop in switch statement switch (*p++) { // case '