Script started on Wed Oct 21 17:34:39 2026 Restored session: Mon Oct 19 18:47:00 EDT 2026 macbook:logs> cat ~/Desktop/q15.txt char *duplicate(const char *p) { char *q; strcpy(q,p); return q; } Is the problem with the above code: a). "const" is not a keyword in C b). "strcpy" cannot take pointers as args c). q does not point to allocated memory d). You cannot return a pointer from a function macbook:logs> echo s1 = computer s1 = computer macbook:logs> echo s1 = computerscience s1 = computerscience macbook:logs> echo "strlen(s1) = 15" strlen(s1) = 15 macbook:logs> ech "15 - 6 = 9" zsh: command not found: ech macbook:logs> echo "15 - 6 = 9" 15 - 6 = 9 macbook:logs> echo "s1 = computers_ience (underscore is for null char)" s1 = computers_ience (underscore is for null char) macbook:logs> cd ../programs/C_ch13 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> 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> cd ../C_ch2 macbook:C_ch2> cat typedef.c /* typedef allows for user-defined types */ #include typedef short int Int16; int main (void) { Int16 a = 4; printf("the number is %d\n", a); return 0; } macbook:C_ch2> cd ../C_ch16 macbook:C_ch16> cat C_ch16_3b.c #include typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; int main() { Part part1, part2; part1.number = 3; part1.name = "wrench"; // Why does this not work? part1.on_hand = 1; printf("Part number %d with name \"%s\" has %d units here.\n", part1.number, part1.name, part1.on_hand); return 0; } macbook:C_ch16> gcc C_ch16_3b.c C_ch16_3b.c:5:15: error: use of undeclared identifier 'NAME_LEN' 5 | char name[NAME_LEN + 1]; | ^ 1 error generated. macbook:C_ch16> cat C_ch16_3b.c #include #define NAME_LEN 100 typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; int main() { Part part1, part2; part1.number = 3; part1.name = "wrench"; // Why does this not work? part1.on_hand = 1; printf("Part number %d with name \"%s\" has %d units here.\n", part1.number, part1.name, part1.on_hand); return 0; } macbook:C_ch16> gcc C_ch16_3b.c C_ch16_3b.c:15:16: error: array type 'char[101]' is not assignable 15 | part1.name = "wrench"; // Why does this not work? | ~~~~~~~~~~ ^ 1 error generated. macbook:C_ch16> cat C_ch16_3b.c #include #define NAME_LEN 100 typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; int main() { Part part1, part2; part1.number = 3; strncpy(part1.name, "wrench", NAME_LEN); part1.on_hand = 1; printf("Part number %d with name \"%s\" has %d units here.\n", part1.number, part1.name, part1.on_hand); return 0; } macbook:C_ch16> gcc C_ch16_3b.c C_ch16_3b.c:15:5: error: call to undeclared library function 'strncpy' with type 'char *(char *, const char *, unsigned long)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 15 | strncpy(part1.name, "wrench", NAME_LEN); | ^ C_ch16_3b.c:15:5: note: include the header or explicitly provide a declaration for 'strncpy' 1 error generated. macbook:C_ch16> gcc C_ch16_3b.c macbook:C_ch16> cat C_ch16_3b.c #include #include "strings.h" #define NAME_LEN 100 typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; int main() { Part part1, part2; part1.number = 3; strncpy(part1.name, "wrench", NAME_LEN); part1.on_hand = 1; printf("Part number %d with name \"%s\" has %d units here.\n", part1.number, part1.name, part1.on_hand); return 0; } macbook:C_ch16> gcc C_ch16_3b.c macbook:C_ch16> ./a.out Part number 3 with name "wrench" has 1 units here. macbook:C_ch16> gcc C_ch16_3c.c macbook:C_ch16> cat C_ch16_3c.c #include #include "strings.h" #define NAME_LEN 100 typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; int main() { Part part1, part2; part1.number = 3; strncpy(part1.name, "wrench", NAME_LEN); part1.on_hand = 1; part2.number = 4; strncpy(part2.name, "hammer", NAME_LEN); part2.on_hand = 8; printf("Part number %d with name \"%s\" has %d units here.\n", part1.number, part1.name, part1.on_hand); printf("Part number %d with name \"%s\" has %d units here.\n", part2.number, part2.name, part2.on_hand); return 0; } macbook:C_ch16> ./a.out Part number 3 with name "wrench" has 1 units here. Part number 4 with name "hammer" has 8 units here. macbook:C_ch16> cat struct_return.c #include #include #define NAME_LEN 100 typedef struct { int number; char name[NAME_LEN + 1]; int on_hand; } Part; Part part1, part2; Part build_part(int number, const char * name, int on_hand) { Part p; p.number = number; strcpy(p.name, name); p.on_hand = on_hand; return p; } int main() { part1 = build_part(3, "abc", 1); printf(" number %d\n", part1.number); printf(" name [%s]\n", part1.name); printf(" onhand %d\n", part1.on_hand); return 0; } macbook:C_ch16> gcc struct_return.c macbook:C_ch16> ./a.out number 3 name [abc] onhand 1 macbook:C_ch16> exit Saving session... ...saving history...truncating history files... ...completed. Deleting expired sessions...none found. Script done on Wed Oct 21 18:42:01 2026