Lecture 12: April 28, 2023
Reading: zyBooks text, ยง5.5, 5.9, 5.11, 10
Assignments: Homework 2 and Extra Credit 2, due May 10
- Announcements
- Gradescope entries for homework 2 and extra credit 2 are there now
- Tutoring available from the CS Tutoring Club; sign up information in an announcement
- Array of strings [echo.c, echo2.c]
- Operators
- Comma operator ,
- a = ( y , z ) means evaluate y, evaluate z, set value of a to value of z
- Example 1: a = 5, b = 2; x = ( a = a+5, b++) sets a to 10, b to 3, and x to 2
- Example 2: prompting; while(printf("> "), scanf("%d", &x) != EOF)
- String library functions
- Prototypes in include file string.h
- String length: strlen(str)
- String copy: strcpy(dest, src); strncpy(dest, src, number_chars)
- String catenation: strcat(dest, src); strncat(dest, src, number_chars)
- String comparison: strcmp(dest, src); strncmp(dest, src, number_chars)
- Recursive greatest common divisor
- Go through Euclidean algorithm for computing gcd
- Walk through function gcd, with m = 4 and n = 6
- Do it again with m = 126 and n = 28
- Go through program gcd.c