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

  1. Announcements
    1. Gradescope entries for homework 2 and extra credit 2 are there now
    2. Tutoring available from the CS Tutoring Club; sign up information in an announcement

  2. Array of strings [echo.c, echo2.c]

  3. Operators
    1. Comma operator ,
      1. a = ( y , z ) means evaluate y, evaluate z, set value of a to value of z
      2. Example 1: a = 5, b = 2; x = ( a = a+5, b++) sets a to 10, b to 3, and x to 2
      3. Example 2: prompting; while(printf("> "), scanf("%d", &x) != EOF)

  4. String library functions
    1. Prototypes in include file string.h
    2. String length: strlen(str)
    3. String copy: strcpy(dest, src); strncpy(dest, src, number_chars)
    4. String catenation: strcat(dest, src); strncat(dest, src, number_chars)
    5. String comparison: strcmp(dest, src); strncmp(dest, src, number_chars)

  5. Recursive greatest common divisor
    1. Go through Euclidean algorithm for computing gcd
    2. Walk through function gcd, with m = 4 and n = 6
    3. Do it again with m = 126 and n = 28
    4. Go through program gcd.c

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 36A, Programming & Problem Solving
Version of April 28, 2023 at 11:29PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh