Programming Assignment 1: It’s a GDTBATH

COMP 211-002 | Spring 2023 (Bakita)

These steps were last updated .

Due Date

Thursday, January 26th, 11:59 PM.


This assignment is intended to show you that simple, but non-trivial, C programs are within your reach.

Things you should know

There are two key things you’ll need to know about C for this assignment:

And from Java (or other languages):

Things you’ll learn

Things you’ll learn in this assignment:

Platform and Access

The server at address has been set up for you all to use throughout this assignment. You should not need to install any software on your computer, and will complete assignments on our server accessed via the Secure SHell (SSH) protocol. The canonical SSH client implementation comes from the OpenSSH project, and is included as the ssh command on Windows 10+ (as of autumn 2018), most Linux distributions, and macOS. There are ssh implementations available for almost every platform, and I heavily use JuiceSSH on Android.

Edit Notice, Jan 18, 9:30 AM: The below instructions have been updated to work around the issue that will not accept your logins due to “an ITS requirement for Onyen authentication.”

Connecting from On-Campus

To access our server, you’ll use the ssh command as follows:

  1. Open a terminal (macOS and Linux) or cmd.exe (Windows).
  2. Run the command ssh, where ONYEN is replaced with your Onyen.
  3. At the prompt, enter your Onyen password (note that no characters will appear) and press enter.
  4. You are now connected to and logged into a bash terminal on Congratulations!

Connecting from Off-Campus

ITS has recently blocked direct off-campus access to most department servers, requiring the use of a VPN.

The official way to connect to our server:

  1. Install and activate the university VPN.
  2. Continue with Step #1 of Connecting from On-Campus.

The way to connect if you despise VPNs on principle:

  1. Open a terminal (macOS and Linux) or cmd.exe (Windows)
  2. Run the command ssh -J, where ONYEN is replaced with your Onyen.
  3. At's password: prompt, type the password listed on Sakai and press Enter.
  4. Continue with Step #3 of Connecting from On-Campus.

Warning: This second approach to connect to the class server is provided on a best-effort basis. The -J parameter to SSH tells it to use one of my research machines,, as a proxy for connecting to This research machine is a small embedded board, and may crash under high load (such as immediately before an assignment is due).

Key information:

  1. To run commands in the terminal, simply type them at the prompt (username@comp211-2sp23:~$) and press enter. Most commands and file names can be autocompleted by hitting the Tab key after you have typed a unique prefix.
  2. The man command should become your close friend. This should give you detailed information about how to use any C library function, program, or tool on the course servers. Use man by typing man <name of function/library/program you want information on>, where the part in <> is replaced. Use arrow keys or page up/down to navigate a manpage, and press q to exit man and return to the command prompt.
  3. As the gcc manual page is voluminous, it should be sufficient to know that running gcc gdtbath.c -o gdtbath will compile gdtbath.c into the executable gdtbath (which can be run as ./gdtbath).

Manpages for tools you may want to consult:

From lecture three:

Quick reference slide from lecture three.
Quick reference slide from lecture three.

Want a break? Try running sl or cmatrix (press q to exit cmatrix).

Requirements Specification

You are to write a program gdtbath in gdtbath.c which takes no parameters or arguements, and outputs the following:

username@comp211-2sp23:~$ ./gdtbath
Hello! username thinks it's a GDTBATH!

Where username is the Onyen of the user running your program (you will have to get this programatically, see man getlogin). Note how the program prints a newline so that the command prompt appears after your text, rather than at the end of it.

Furthermore, if the user’s console supports color, GDTBATH! should appear in light blue (#00ffff i.e. RGB(0,255,255)). (You can alternatively use indexed color code 51, which also maps to #00ffff in my terminal.) For the purposes of this assignment, “supports color” means that the TERM environment variable equals xterm-256color. See man getenv for how to get the value of an environment variable, and man string for a listing of C standard library functions for ‘string’ (really just character array) manipulation. (Section B3 of K&R also contains similar information to man string.) Each function should have its own man page, man string just provides an index/overview. You will need to find a function for string comparison, such that you can check the value of the TERM environment variable is something that supports color.

Extra Credit Opportunity: Print in color on other terminals that support it, like screen-256color. Make sure that you continue to not print color for terminals without support, like vt220 or vt100. The man pages for term (in manual section 7) and terminfo (in manual section 5) should be helpful. (Note that while the term manpage states that terminal descriptions are stored as files under /etc/terminfo, they are instead under /lib/terminfo and /usr/share/terminfo on the course server. The command tree /lib/terminfo may be helpful here.) Good implementations of this will receive extra credit points in style grading. For unrecognized terminals, you should default to printing without color.

Edit Notice, Jan 25, 10:30 AM: The above extra credit instructions have been updated to fix the infocmp reference and add the secondary terminfo database path /usr/share/terminfo. The default manpage shown if you run man infocmp is in section 3ncurses, whereas I was originally referencing section 5 (ncurses was installed after this assignment was written). ncurses is likely not going to be the right tool for this assignment. For more complicated programs, ncurses may be the way to go. Here, we’ve just trying to determine if the console supports 24-bit color—this is not something that we’re aware ncurses provides an API for. (Note that consoles which support 8 or 16 colors will not necessarily print “blue” or “cyan” in those colors, my terminal allows them to be configured for example.) The autograder will build your program as gcc gdtbath.c -o gdtbath, and so you will not have the opportunity to link in curses. (Unless you provide a very convincing counter-argument.)

Collaboration Policy: As stated in the syllabus.

Submission Instructions


Subject to change, current as of Jan 18, 9:30 AM.

As it is possible to write a C program that appears to work, but does so unreliably due to memory corruption, we will check for memory correctness with valgrind. Up to 25% may be lost in any of the above autograded categories if your program corrupts memory for those tests.

Note that the autograder will only perform a subset of the tests prior to the deadline. Finding and fixing edge cases in your code is a frequent necessity in interviews and industry work.

Honor Code Pledge

The first line in your submission file (gdtbath.c) must be the following:

// I, John Doe (730777777), pledge that I have neither given nor received unauthorized aid on this assignment.

Where John Doe is replaced with your name, and 730777777 is replaced with your PID. This statement constitutes your legally binding signature.

If you collaborated with any students on your assignment submission, you must list them as collaborators on the second line of your submission, as follows:

// Collaborators: onyenA, onyenB

Where onyenA and onyenB would be replaced with the Onyens of your first two collaborators. This comma-separated list may name any number of collaborators. Remember, per the syllabus, any form of code sharing is strictly forbidden. Your “collaborators” listed here are simply those you non-trivially discussed high-level concepts, approaches, and pseudocode ideas with (as defined in the syllabus).

If you are finding this assignment insurmountably difficult, note that you have until 5 PM on Jan. 23rd to drop this class without receiving a ‘W’ grade.

To Submit…

  1. Make sure you can log in to Gradescope through the link on Sakai.
  2. Run submit_a1 <path to your gdtbath.c file> on the course server, with the path to your implementation of gdtbath.c.
  3. Log in (no characters will appear while you enter your password).
  4. After you see File "<your file name>" uploaded., your submission is uploaded to Gradescope.
  5. [Optional] Log in to Gradescope and verify that your submission for assignment 1 uploaded correctly.

You have unlimited resubmissions before the deadline, and may repeat the above process as many times as is necessary to update your submission.

Autograder is live as of 11 PM on Jan 24.