Script started on Mon Oct 19 17:32:03 2026 Restored session: Thu Oct 15 08:52:52 EDT 2026 macbook:Desktop> cat q14.txt Which of the following are correct? 1. char date1[8] = {'O', 'c', 't', ' ', '1', '9', '\0'}; 2. char date1[8] = "Oct 19"; 3. char date1[] = "Oct 19"; macbook:Desktop> vi strncat_example.c macbook:Desktop> gcc strncat_example.c macbook:Desktop> cat strncat_example.c #include #include int main() { char first[] = "Stan"; char last[] = "Smith"; char both_names[100]; strncpy(both_names, first, 100); strncat(both_names, last, 100); printf("The full name is \"%s\"\n", both_names); return 0; } macbook:Desktop> ./a.out The full name is "StanSmith" macbook:Desktop> vi strncat_example.c macbook:Desktop> gcc strncat_example.c macbook:Desktop> cat strncat_example.c #include #include int main() { char first[] = "Stan"; char last[] = "Smith"; char both_names[100]; strncpy(both_names, first, 100); strncat(both_names, " ", 100); strncat(both_names, last, 100); printf("The full name is \"%s\"\n", both_names); return 0; } macbook:Desktop> ./a.out The full name is "Stan Smith" macbook:Desktop> cp strncat_example.c strncmp_example.c macbook:Desktop> vi strncmp_example.c macbook:Desktop> gcc strncmp_example.c macbook:Desktop> cat strncmp_example.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "abc", 6); // str1 = "abc" strncpy(str2, "abc", 6); strncat(str2, "def", 6); // str2 = "abcdef" if (strncmp(str1,str2, 3)<0) /* is str1 <= str2 ? True*/ printf("str1 is <= str2\n"); else printf("str1 is NOT <= str2\n"); return 0; } macbook:Desktop> ./a.out str1 is NOT <= str2 macbook:Desktop> vi strncmp_example.c macbook:Desktop> gcc strncmp_example.c macbook:Desktop> cat strncmp_example.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "abc", 6); // str1 = "abc" strncpy(str2, "abc", 6); strncat(str2, "def", 6); // str2 = "abcdef" if (strncmp(str1,str2, 6)<0) /* is str1 <= str2 ? True*/ printf("str1 is <= str2\n"); else printf("str1 is NOT <= str2\n"); return 0; } macbook:Desktop> ./a.out str1 is <= str2 macbook:Desktop> vi strncmp_example.c macbook:Desktop> cat strncmp_example.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "abc", 6); // str1 = "abc" strncpy(str2, "abc", 6); strncat(str2, "def", 6); // str2 = "abcdef" if (strncmp(str1,str2, 6)<0) /* is str1 < str2 ? True*/ printf("str1 is <= str2\n"); else printf("str1 is NOT <= str2\n"); return 0; } macbook:Desktop> vi strncmp_example.c macbook:Desktop> gcc strncmp_example.c macbook:Desktop> cat strncmp_example.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "abc", 6); // str1 = "abc" strncpy(str2, "abc", 6); strncat(str2, "def", 6); // str2 = "abcdef" if (strncmp(str1,str2, 6)<0) /* is str1 < str2 ? True*/ printf("str1 is < str2\n"); else printf("str1 is NOT < str2\n"); return 0; } macbook:Desktop> cp strncmp_example.c strncmp_example_v2.c macbook:Desktop> vi strncmp_example_v2.c macbook:Desktop> gcc strncmp_example_v2.c macbook:Desktop> cat strncmp_example_v2.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "xyz", 6); // str1 = "abc" strncpy(str2, "xyz", 6); if (strncmp(str1,str2, 6)) /* is str1 == str2 ? */ printf("str1 is equal to str2\n"); else printf("str1 is NOT equal to str2\n"); return 0; } macbook:Desktop> ./a.out str1 is NOT equal to str2 macbook:Desktop> cp strncmp_example_v2.c strncmp_example_v3.c macbook:Desktop> vi strncmp_example_v3.c macbook:Desktop> gcc strncmp_example_v3.c macbook:Desktop> cat strncmp_example_v3.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "xyz", 6); // str1 = "abc" strncpy(str2, "xyz", 6); if (strncmp(str1,str2, 6) == 0) /* is str1 == str2 ? */ printf("str1 is equal to str2\n"); else printf("str1 is NOT equal to str2\n"); return 0; } macbook:Desktop> ./a.out str1 is equal to str2 macbook:Desktop> cp strncmp_example_v3.c strncmp_example_v4.c macbook:Desktop> vi strncmp_example_v4.c macbook:Desktop> gcc strncmp_example_v4.c macbook:Desktop> cat strncmp_example_v4.c #include #include int main() { char str1[7]; char str2[7]; strncpy(str1, "xyz", 6); // str1 = "abc" strncpy(str2, "wxy", 6); printf(" str1 = \"%s\", str2 = \"%s\" \n", str1, str2); if (strncmp(str1,str2, 6) == 0) /* is str1 == str2 ? */ printf("str1 is equal to str2\n"); else if (strncmp(str1,str2, 6) < 0) printf("str1 is less than str2\n"); else printf("str1 is greater than str2\n"); return 0; } macbook:Desktop> ./a.out str1 = "xyz", str2 = "wxy" str1 is greater than str2 macbook:Desktop> cd csc3320_Fall2026/programs/C_ch13/args.c cd: not a directory: csc3320_Fall2026/programs/C_ch13/args.c macbook:Desktop> cd csc3320_Fall2026/programs/C_ch13/ macbook:C_ch13> cat args.c /********************************************************* * From C PROGRAMMING: A MODERN APPROACH, Second Edition * * By K. N. King * * Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. * * All rights reserved. * * This program may be freely distributed for class use, * * provided that this copyright notice is retained. * *********************************************************/ // This is based on code from the above book #include #include int main(int argc, char *argv[]) { for (int i=0; i< argc; i++) printf("arg %d is %s \n", i, argv[i]); return 0; } macbook:C_ch13> gcc args.c -o args macbook:C_ch13> ./args arg 0 is ./args macbook:C_ch13> ./args hickory arg 0 is ./args arg 1 is hickory macbook:C_ch13> ./args hickory oak arg 0 is ./args arg 1 is hickory arg 2 is oak macbook:C_ch13> ./args hickory oak maple palm cherry arg 0 is ./args arg 1 is hickory arg 2 is oak arg 3 is maple arg 4 is palm arg 5 is cherry macbook:C_ch13> cdd macbook:Desktop> ls *.c q13b.c strncmp_example_v2.c strncmp_example_v4.c strncat_example.c strncmp_example_v3.c strncmp_example.c macbook:Desktop> cp strncmp_example.c str_ex1.c macbook:Desktop> vi str_ex1.c macbook:Desktop> gcc str_ex1.c macbook:Desktop> cat str_ex1.c #include #include char *duplicate(const char *p) { char *q; strcpy(q,p); return q; } int main() { char *myduplicate; myduplicate = duplicate("abcdef"); printf(" the duplicate is \"%s\" \n", myduplicate); return 0; } macbook:Desktop> echo "this should not work" this should not work macbook:Desktop> ./a.out zsh: segmentation fault ./a.out macbook:Desktop> cp str_ex1.c str_ex1b.c macbook:Desktop> vi str_ex1b.c macbook:Desktop> gcc str_ex1b.c macbook:Desktop> ./a.out the duplicate is "abcdef" macbook:Desktop> macbook:Desktop> exit Saving session... ...saving history...truncating history files... ...completed. Deleting expired sessions...none found. Script done on Mon Oct 19 18:47:01 2026