Manipulating A C - STRINGS AS AN ARRAY OF CHARACTERS Flashcards
testing the value of a character
functions test a single char argument for a specific quality and return true or false
isupper
function in the header that tests to see if a character is an uppercase letter
isalpha
function in the header that tests to see if a character is a letter of the alphabet
isalnum
function in the header that tests to see if a character is a letter of the alphabet or a digit
isdigit
function in the header that tests to see if a character is a digit from 0 to 9
islower
function in the header that tests to see if a character is a lowercase letter
isprint
function in the header that tests to see if a character is a PRINTABLE CHARACTER including a space (basically as far as I can tell, not the null terminator)
ispunct
function in the header that tests to see if a character is a PRINTABLE CHARACTER other than a digit, letter, or space
isspace
function in the header that tests to see if a character is a whitespace characterspace ‘ ‘newline \nvertical tab \vtab \t
toupper
function in the header that returns the uppercase equivalent of a char-type argument (w/o changing the original as per C++ usual). Will return an uppercase letter or nonletter argument unchangedcout «_space;toupper(‘a’) for instance
tolower
function in the header that returns the lowercase equivalent of a char-type argument (w/o changing the original as per C++ usual). Will return a lowercase letter or nonletter argument unchangedcout «_space;tolower(‘A’) for instance
string
generic term that describes any consecutive sequence of characters
C-string
string whose characters are stored in consecutive memory locations and are followed by the null terminator (ASCII 0). Basically a char array with space for each character, +1 for the null terminatorString literals/constants are stored as C-strings
implicit sizing - char array
“since a string literal is itself read as an array, and the computer notices the number of characters, you can initialize an array with a string literalchar characterarray[] = ““Grace”” which will have 6 spotsand those spots will be filled byG r a c e \0but you can write over them”
c-string console input
“char characterarray[21];cin»_space; characterarray;in the second line, ““characterarray”” is a variable that represents the array with the pointer at the beginning of itcin will write past the end of the array if you cin more than 21 characters. I think this is called overloading. in any case, cin.getline()”
cin.getline() for c-strings and character arrays
cin.getline(stordes, MAXLN);and then you type stuff and hit ENTER when you’re donestordes is the storage destination. Because it’s a string literal, it’ll be stored in a character array. The name of the array by itself represents the array with the pointer reset to index at 0.maxln (constant integer) is the maximum length of the input, so usually the size of the array. Because the input includes the null terminator, an 80-index array will intake 79 values. If the input isn’t that long, it’ll append the null terminator at the end of the input.it does NOT truncate the array to the size of the string