Script started on Mon Oct 20 17:28:16 2025 macbook:logs> cd ../programs/C_ch13 macbook:C_ch13> echo attendance code 413 attendance code 413 macbook:C_ch13> man string macbook:C_ch13> cat string_example.c #include #include int main(){ char date1[] = {'J', 'u', 'n', 'e', ' ', '1', '4', '\0'}; char date2[] = "October 18"; // strcpy -> strncpy // strlen -> strnlen // strcat -> strncat // strcpy //strcpy(date1, date2); strncpy(date1, date2, 7); printf("%s \n", date1); printf("%s \n", date2); return 0; } macbook:C_ch13> gcc string_example.c macbook:C_ch13> ./a.out October October 18 macbook:C_ch13> cp string_example.c str1.c macbook:C_ch13> vi str1.c macbook:C_ch13> gcc str1.c macbook:C_ch13> ./a.out date1: June 14 date2: October 18 now we make a change date1: October date2: October 18 macbook:C_ch13> cat str1.c #include #include int main(){ char date1[] = {'J', 'u', 'n', 'e', ' ', '1', '4', '\0'}; char date2[] = "October 18"; printf("date1: %s \n", date1); printf("date2: %s \n", date2); printf(" now we make a change\n"); // strcpy -> strncpy // strlen -> strnlen // strcat -> strncat // strcpy //strcpy(date1, date2); strncpy(date1, date2, 7); printf("date1: %s \n", date1); printf("date2: %s \n", date2); return 0; } macbook:C_ch13> gcc str1.c macbook:C_ch13> ./a.out date1: June 14 date2: October 18 now we make a change date1: October date2: October 18 macbook:C_ch13> macbook:C_ch13> cat string_example2.c #include #include int main(){ char date1[] = {'J', 'u', 'n', 'e', ' ', '1', '4', '\0'}; char date2[] = "October 18"; // strcpy -> strncpy // strlen -> strnlen // strcat -> strncat // strcpy //strcpy(date1, date2); int c = strncmp(date1, date2, 7); printf("%s \n", date1); printf("%s \n", date2); printf("cmp returns %d \n", c); c = strncmp(date1, date1, 7); printf("cmp returns %d \n", c); return 0; } macbook:C_ch13> gcc string_example2.c macbook:C_ch13> ./a.out June 14 October 18 cmp returns -5 cmp returns 0 macbook:C_ch13> cp string_example2.c string_example2b.c macbook:C_ch13> vi string_example2b.c macbook:C_ch13> gcc string_example2b.c macbook:C_ch13> ./a.out June 14 October 18 cmp(date1, date2) returns -5 cmp(date2, date1) returns 5 cmp(date1, date1) returns 0 macbook:C_ch13> cp string_example2b.c string_example2c.c macbook:C_ch13> vi string_example2c.c macbook:C_ch13> cat string_example2c.c #include #include int main(){ char date1[] = "Octobeq 18"; char date2[] = "October 18"; // strcpy -> strncpy // strlen -> strnlen // strcat -> strncat // strcpy //strcpy(date1, date2); int c = strncmp(date1, date2, 7); printf("%s \n", date1); printf("%s \n", date2); printf("cmp(date1, date2) returns %d \n", c); c = strncmp(date2, date1, 7); printf("cmp(date2, date1) returns %d \n", c); c = strncmp(date1, date1, 7); printf("cmp(date1, date1) returns %d \n", c); return 0; } macbook:C_ch13> gcc string_example2c.c macbook:C_ch13> ./a.out Octobeq 18 October 18 cmp(date1, date2) returns -1 cmp(date2, date1) returns 1 cmp(date1, date1) returns 0 macbook:C_ch13> cp string_example2c.c string_example2d.c macbook:C_ch13> vi string_example2d.c macbook:C_ch13> gcc string_example2d.c macbook:C_ch13> ./a.out abcdef abc cmp(date1, date2) returns 100 cmp(date2, date1) returns -100 cmp(date1, date1) returns 0 macbook:C_ch13> cat string_example2d.c #include #include int main(){ char date1[10] = "abcdef"; char date2[10] = "abc"; // strcpy -> strncpy // strlen -> strnlen // strcat -> strncat // strcpy //strcpy(date1, date2); int c = strncmp(date1, date2, 7); printf("%s \n", date1); printf("%s \n", date2); printf("cmp(date1, date2) returns %d \n", c); c = strncmp(date2, date1, 7); printf("cmp(date2, date1) returns %d \n", c); c = strncmp(date1, date1, 7); printf("cmp(date1, date1) returns %d \n", c); return 0; } macbook:C_ch13> vi what_will_be.c macbook:C_ch13> gcc what_will_be.c what_will_be.c:6:8: error: use of undeclared identifier 's1' 6 | strcpy(s1,"computer"); | ^ what_will_be.c:6:8: error: use of undeclared identifier 's1' what_will_be.c:7:8: error: use of undeclared identifier 's2' 7 | strcpy(s2,"science"); | ^ what_will_be.c:7:8: error: use of undeclared identifier 's2' what_will_be.c:8:12: error: use of undeclared identifier 's1' 8 | if (strcmp(s1,s2) < 0) | ^ what_will_be.c:8:15: error: use of undeclared identifier 's2' 8 | if (strcmp(s1,s2) < 0) | ^ what_will_be.c:9:8: error: use of undeclared identifier 's1' 9 | strcat(s1,s2); | ^ what_will_be.c:9:11: error: use of undeclared identifier 's2' 9 | strcat(s1,s2); | ^ what_will_be.c:9:8: error: use of undeclared identifier 's1' 9 | strcat(s1,s2); | ^ what_will_be.c:11:8: error: use of undeclared identifier 's2' 11 | strcat(s2,s1); | ^ what_will_be.c:11:11: error: use of undeclared identifier 's1' 11 | strcat(s2,s1); | ^ what_will_be.c:11:8: error: use of undeclared identifier 's2' 11 | strcat(s2,s1); | ^ what_will_be.c:12:1: error: use of undeclared identifier 's1' 12 | s1[strlen(s1) - 6]='\0'; | ^ what_will_be.c:12:11: error: use of undeclared identifier 's1' 12 | s1[strlen(s1) - 6]='\0'; | ^ what_will_be.c:13:25: error: use of undeclared identifier 's1' 13 | printf(" s1 is [%s]\n", s1); | ^ 15 errors generated. macbook:C_ch13> vi what_will_be.c macbook:C_ch13> gcc what_will_be.c macbook:C_ch13> ./a.out s1 is [computers] macbook:C_ch13> vi what_will_be.c macbook:C_ch13> gcc what_will_be.c macbook:C_ch13> ./a.out s1 is [computer] s2 is [science] After strcat s1 is [computerscience] s2 is [science] After inserting null char s1 is [computers] s2 is [science] (same as before) macbook:C_ch13> cat what_will_be.c #include #include int main() { char s1[100]; char s2[100]; strcpy(s1,"computer"); strcpy(s2,"science"); printf("s1 is [%s]\n", s1); printf("s2 is [%s]\n", s2); if (strcmp(s1,s2) < 0) strcat(s1,s2); else strcat(s2,s1); printf("After strcat\n"); printf("s1 is [%s]\n", s1); printf("s2 is [%s]\n", s2); s1[strlen(s1) - 6]='\0'; printf("After inserting null char\n"); printf("s1 is [%s]\n", s1); printf("s2 is [%s] (same as before) \n", s2); return 0;} macbook:C_ch13> cd ../C_ch16 macbook:C_ch16> grep build *.c C_ch16_6.c:struct part build_part(int number, macbook:C_ch16> cat C_ch16_6.c struct part build_part(int number, const char * name, int on_hand) { struct part p; p.number = number; strcpy(p.name, name); p.on_hand = on_hand; return p; } macbook:C_ch16> cp C_ch16_6.c struct_return.c macbook:C_ch16> vi struct_return.c macbook:C_ch16> gcc struct_return.c struct_return.c:6:13: error: use of undeclared identifier 'NAME_LEN' 6 | char name[NAME_LEN + 1]; | ^ struct_return.c:15:17: error: variable has incomplete type 'struct part' 15 | struct part p; | ^ struct_return.c:15:12: note: forward declaration of 'struct part' 15 | struct part p; | ^ 2 errors generated. macbook:C_ch16> vi struct_return.c macbook:C_ch16> gcc struct_return.c struct_return.c:6:13: error: use of undeclared identifier 'NAME_LEN' 6 | char name[NAME_LEN + 1]; | ^ 1 error generated. macbook:C_ch16> vi struct_return.c macbook:C_ch16> gcc struct_return.c macbook:C_ch16> ./a.out number 3 name [abc] onhand 1 macbook:C_ch16> exit Saving session... ...copying shared history... ...saving history...truncating history files... ...completed. Deleting expired sessions... 2 completed. Script done on Mon Oct 20 18:45:33 2025