MAT 21B Lecture Notes - Lecture 17: Newline, Substring, Null Character
![](https://new-preview-html.oneclass.com/rwz4BW6gGqbajYlpwkKnmvLP3edVpolX/bg1.png)
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
![MAT 21B Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2365737-class-notes-us-uc-davis-mat-21b-lecture13.jpg)
83
MAT 21B Full Course Notes
Verified Note
83 documents