MAT 21B Lecture Notes - Lecture 17: Newline, Substring, Null Character
Lecture 17
String assignment and copy
- Assigning an existing string to a pointer makes the pointer point at the sae string
- Strcopy() can be a copy a sting into another string
- Refer to ppt for line of code
Sting copy and substring
- Strcpy() takes a destination, a cource and maximum number of characters to copy
o Useful for substrings
o And preventing overflow
o Character ‘/tetha’ is equivalent to the numerical value of tetha
o An array reference with no subscript represent the address of the first element
▪ Course +3 to get to the address of the character at located three positions
away from the beginning
▪ Equivalent to &couse[3]
String concatenation
o Strcat() to append a string to an already existing string
▪ Potential risk of overflow
o Strncat() to specify the maximum number of characters
String input
o Fgets() properties
▪ Will never read more than max
▪ Will always end the resulting sting with a null character
▪ Can read from various input streams
▪ Does not skip leading whitespace characters
▪ Stops on the first newline or when reaching the maximum size
▪ Includes the newline as part of the string
find more resources at oneclass.com
find more resources at oneclass.com
beigecamel74 and 41 others unlocked
83
MAT 21B Full Course Notes
Verified Note
83 documents