COM SCI 31 Lecture Notes - Lecture 5: C String Handling, Null Character, Concatenation

48 views2 pages
25 Mar 2017
School
Professor

Document Summary

C string = one-dimensional array of characters (char) terminated by a null character. Tri(cid:374)g str = (cid:862)i a(cid:373) hu(cid:374)gry! (cid:863); Char str[] = {(cid:858)o(cid:859), (cid:858)k(cid:859), (cid:858)! (cid:859), (cid:858)\0(cid:859)}; Concatenation of c++ strings strcat(str1, str2); strcpy(str, strcat(str1, str2)); for c++: str = str1 + str2; Comparing c strings if(strcmp(str1, str2) <0: same as if(str 1 < str 2) in c++ if(strcmp(str1, str2) == 0) if(strcmp(str1, str2) > 0) Size of a c string char str[] = (cid:862)test! (cid:863); strlen(str); Arrays provide a way to group data on a principle of data type structures provide a way to group data logically (various data types) struct product int weight; float price; // struct can hold more than one type of data types while arrays only hold one type product apple; apple. weight = 10; apple. price = 20; // must use the (dot) operator to specify.

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 Questions