UP | HOME

HW16
COP-3223H

Setup

See HW7's Setup for how to prepare for performing and submitting your homework.

Homework file names

  • hw16-1.c
  • hw16-2.c

Questions

  1. (hw16-1.c) Hand-copy yourself without copy-and-paste the following program into a file on eustis and compile and run it.

    #include <stdio.h>
    #include <unistd.h>
    
    int main(int argc, char **argv) {
      int width = 40;
      int height = 20;
      int x = 1;
      int y = 1;
      int dx = 1;
      int dy = 1;
      while (1) {
        printf("\033[2J");
        printf("\033[H");
        printf("\033[%d;%dH", (int)y, (int)x);
        putchar('o');
        putchar('\n');
        if ((0 < (x + dx)) && ((x + dx) <= width)) {
          dx = dx;
        } else {
          dx = dx * -1;
        }
        if ((0 < (y + dy)) && ((y + dy) <= height)) {
          dy = dy;
        } else {
          dy = dy * -1;
        }
        printf("\033[%d;%dH", height + 2, 0);
        printf("y: %d\n", y);
        printf("x: %d\n", x);
        x = x + dx;
        y = y + dy;
        usleep(50 * 1000);
      }
      return 0;
    }
    
  2. (hw16-2.c) Write a program, using either the ANSI cursor movements shown in class or nested while loops, that draws a diagonal "line" of character o from terminal position (0,0) to (10,10) exclusive. The output should look like this:

    o
     o
      o
       o
        o
         o
          o
           o
            o
    

Submission

See HW7's Submission instructions for adding, committing, and pushing your homework to the assignments' repo.

Self-check

See HW7's Self-check for instructions on checking what you have submitted to the remote grading repository.

Author: Paul Gazzillo

Created: 2026-02-24 Tue 15:11

Validate