Characters, Strings, and the cstring library
- Recall that a C-style string is a character array that ends with
the null character
- Character literals in single quotes
- string literals in double quotes
- "Hello World\n"
- Remember that the null-character is implicitly a part of any string
- The name of an array acts as a pointer to the first element of an
array (i.e. it stores the address of where the array starts)
- Recall that this means when an array is passed into a function, the
function has access to the original array contents
Recap: the cctype library
Recall that this C library contains useful character testing functions, as
well as the two conversion functions toupper and tolower
- Conversion functions: These return the ascii value of a
- int toupper(int c) - returns the uppercase version of
c if it's a lowercase letter, otherwise returns c
- int tolower(int c) - returns the lowercase version of
c if it's an uppercase letter, otherwise returns c
- Query Functions: These all return true (non-zero) or false (0),
in answer to the question posed by the function's name. They all take in
the ascii value of a character as a parameter.
- int isdigit(int c) - decides whether the parameter is a
- int isalpha(int c) - decides whether the character is a
letter (a-z, A-Z)
- int isalnum(int c) - digit or a letter?
- int islower(int c) - lowercase digit? (a-z)
- int isupper(int c) - uppercase digit? (A-Z)
- int isxdigit(int c) - hex digit character? (0-9, a-f)
- int isspace(int c) - white space character?
- int iscntrl(int c) - control character?
- int ispunct(int c) - printing character other than space,
- int isprint(int c) - printing character (including ' ')?
- int isgraph(int c) - printing character other than ' '