Manipulating A C - STRINGS AS AN ARRAY OF CHARACTERS Flashcards

1
Q

testing the value of a character

A

functions test a single char argument for a specific quality and return true or false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

isupper

A

function in the header that tests to see if a character is an uppercase letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

isalpha

A

function in the header that tests to see if a character is a letter of the alphabet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

isalnum

A

function in the header that tests to see if a character is a letter of the alphabet or a digit

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

isdigit

A

function in the header that tests to see if a character is a digit from 0 to 9

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

islower

A

function in the header that tests to see if a character is a lowercase letter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

isprint

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ispunct

A

function in the header that tests to see if a character is a PRINTABLE CHARACTER other than a digit, letter, or space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

isspace

A

function in the header that tests to see if a character is a whitespace characterspace ‘ ‘newline \nvertical tab \vtab \t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

toupper

A

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 &laquo_space;toupper(‘a’) for instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

tolower

A

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 &laquo_space;tolower(‘A’) for instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

string

A

generic term that describes any consecutive sequence of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

C-string

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

implicit sizing - char array

A

“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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

c-string console input

A

“char characterarray[21];cin&raquo_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()”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

cin.getline() for c-strings and character arrays

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

strlen

A

“function in the header that returns the length of the c-string argument. NOT counting the null terminator nor the size of the arrayargument can be name of the array, pointer variable (later), or the string literalbecause the argument is the name of the array (not the array w/indexed size), the pointer is set to the beginning so it doesn’t know the size of the array after the null terminatorlength = strlen(arrayname) or =strlen(““Grace””)”

18
Q

sizeof

A

I’m sure I wrote this down in a previous chapter but this counts the value spots in an array (different than strlen!)

19
Q

strcat

A

function in the header that concatenates one string to another. Argument is two C-strings (using their array names sans indices). Be sure to put a space in one of the string literals, because strcat won’t insert it and there’s no space to add it as an argumentcopies the 2nd string over to the end of the 1st. Leaves the 2nd string (saved under its own name) alone, but 1st is changedstrcat(string1, string2);this can overload the bounds of an array

20
Q

strncat

A

function in the header that works like strcat but there’s a third argument specifying the max number of characters from 2nd string to append to 1st stringstrncat(string1, string2, 10);

21
Q

strcpy

A

function in the header that writes one string over another without a loop (or copies a string to an array). I assume this would be used to take one string, multiply it or something, then strcpy it to a new column in a structure or somethingstrcpy(string1, string2);this can overload the bounds of an array

22
Q

strncpy

A

function in the header that works like strcpy but there’s a third argument specifying the max number of characters from 2nd string to copy to the 1ststrncpy(string1, string2, 5);*come back to this

23
Q

strstr

A

“function in the header that searches for a string inside of a string. First argument is the string to be searched and the second is what you’re looking for. It’ll search a c-string character array and return address of the first character of the second stringstring1 = ““blood types A B AB O”“strstr(string1, ““AB”“)I don’t know what would happen if I searched just for A or Bbut apparently it returns the rest of string 1 after starting at the beginning of string 2”

24
Q

strcmp

A

“function in the header (?!?! maybe this is a typo) that compares c-strings, since relational operators won’t workstrcmp(string1, string2)This function will return 0 if the strings are equal on a character-by character basis,-1 if string1 comes BEFORE string2 in alphabetical order1 if string1 comes AFTER string2 in alphabetical orderthis works well with if statements, and you can use the returns with relational operatorsusing ! - the computer sees 0 as false. If your strings are equal, and you want the computer to report ““true”” for that (just because it’s more intuitive) put ! in front of the callif (!strcmp(string1, string2))I don’t think that works if the strings aren’t equal but I’ll test it”

25
Q

stricmp

A

function in the header (?!?! maybe this is a typo) that compares c-strings with no case sensitivity

26
Q

sort strings

A

use strcmp or stricmp to put strings in alphabetical orderif(strcmp(string1, string2) <0 {cout &laquo_space;string1 &laquo_space;’ ‘ <remember, -1 means they’re already in alphabetical order

27
Q

c++ string type (also known as a string object, as opposed to a string literal)

A

“abstract data type/class. Be sure to #include then define it asstring stringName; and assign it withstringName = ““Contents Go Here””; and you can just work with stringName like you would another char variable”

28
Q

reading into a C++ string

A

string stringName;getline(cin, stringName);

29
Q

relational and math operators w/C++ strings

A

, >=, ==, and != compare the ASCII values of the characters in each string, one by oneI don’t know how this works for lower- versus uppercaseyou can use relational operators to compare C++ strings with C strings but as far as I can tell it has to be a string literalstringOne += stringTwo appends a copy of stringTwo to end of stringOnestringOne + stringTwo concatenates the two strings //how is this different from +=? I guess you can save this as a new var

30
Q

assigning a string variable (methods)

A

“string stringName; //emptystring stringName(““here it is””);string newString(stringName); //copy of stringNamestring newString(stringName, 10); //first 10 valuesstring boring(‘z’, 10); //10 z’s in a stringstring middleName(fullName, 5, 10); the values of fullName from 5 to 10”

31
Q

string subscripts []

A

work just like in a C-string arraycplusplusString[0] etc

32
Q

length

A

function in the header that returns the length of the string ~stored in the object~ (what does that mean?)newString.length();

33
Q

size

A

function in the header that returns the length of the string as well (I’m sure this is the spiritual child of sizeof instead of strlen)newString.size();

34
Q

append

A

“function in the header that appends ““n”” copies of ‘z’ to newStringnewstring.append(n, ‘z’);or character-array-slash-string-object chr newstring.append(chr);or the first n characters of chrnewstring.append(chr, n);or a selection of 5 values from chr starting at 20 herenewstring.append(chr, 20, n); //if newstring is too small, it’ll fill it as much as possible (won’t overflow)”

35
Q

assign

A

function in the header that assigns n copies of ‘z’ to the string. I think it’ll write over existing stuff but I’d use this w/empty strings anywaynewstring.assign(n, ‘z’);assigns a string or character array thing_assigned to newstring.assign(thing_assigned);assign the first n characters of thing_assigned to newstringnewstring.assign( thing_assigned, n);assign 5 many characters from thing_assigned starting at 20, to newstring. If newstring is too small, the function will assign as many as possible (won’t overflow)newstring.assign(thing_assigned, 20, 5);

36
Q

at

A

function in the header that returns the character at position 3 (or whatever) in the stringnew_string.at(3);

37
Q

begin

A

function in the header that returns an iterator (ch16?) pointing to the first character in the stringnew_string.begin();

38
Q

c_str

A

function in the header that converts the contents of new_string to a C-string and returns a pointer to the beginning of it. WHY THOnew_string.c_str();

39
Q

capacity

A

function in the header that returns the size of the storage allocated for new_string (in what units? bytes?)new_string.capacity();

40
Q

clear

A

function in the header that deletes everything in the string. Be darned careful