CSC209H1 Lecture Notes - Lecture 4: Null Character, String Literal, Bus Error

76 views5 pages
School
Course
Professor

Document Summary

Instead of initializing strings by each element, you can use an array {} with characters separated by commas: **do(cid:374)"t forget the (cid:374)ull (cid:272)hara(cid:272)ter. Initialized characters hold their values, and non-initialized hold the null character. It is illegal for the initializer (aka the portion in double quotes) to be longer than the char array. If you simply try to add two strings using concatenation i. e. s1 + s2, it will not work as planned as c stores a pointer to the address of the first element/char in each variable. If you want strings to be added cleanly, you must add a space manually, as strcat() does not recognize and do this for you. Just (cid:272)opies ea(cid:272)h (cid:272)hara(cid:272)ter fro(cid:373) s(cid:1006), starti(cid:374)g fro(cid:373) s(cid:1005)"s first (cid:374)ull terminator. If the character is found strstr() returns a pointer to the character of s1 that begins the match with first character of s2.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions