COM SCI 31 Lecture Notes - Lecture 13: C String Handling, Empty String, String Literal

17 views2 pages
14 Aug 2017
School

Document Summary

If (t (cid:858)\(cid:1004)(cid:859) (cid:272)o(cid:374)(cid:448)e(cid:374)tio(cid:374): do(cid:374)(cid:859)t look over zero byte. C st(cid:396)i(cid:374)g: (cid:272)ha(cid:396) t[(cid:1005)(cid:1004)] = (cid:862)hello(cid:863) //dou(cid:271)le (cid:395)uote st(cid:396)i(cid:374)g lite(cid:396)al i(cid:373)plies it(cid:859)s (cid:396)ea(cid:272)hed ze(cid:396)o (cid:271)yte t. size() -> must be c++ string strlen(t) -> must be c string. For (int k = 0; t[k] != \0"; k++) > 0 a less than b if a greater than b. 0 if a equals b positive if a comes after b. Cin. getline(s, 50); //read a line of input into s; store a \0" at the end. Strcpy(s, t); //strcpy(destination, source); make sure destination string is big enough to hold! ! ); //c strings can"t append char, we do it manually. If (strcmp(t, s) < 0) // c++: if (t < 0) if a equal to b wrong: if (strcmp(a,b)) //actually yields the opposite result!

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