HW10
COP-3223H
Submit this project via git (not webcourses) using the Uploading homework to git documentation.
(
hw10-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", y, x); putchar('o'); fflush(stdout); 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; }(
hw10-2.c) Write a program, using either the ANSI cursor movements shown in class or nested while loops, that draws a diagonal "line" of characterofrom terminal position (0,0) to (10,10) exclusive. The output should look like this:o o o o o o o o o