COMP 211-002 | Spring 2023 (Bakita)
These steps were last updated .
Thursday, January 26th, 11:59 PM.
This assignment is intended to show you that simple, but non-trivial, C programs are within your reach.
There are two key things you’ll need to know about C for this assignment:
And from Java (or other languages):
if/else statements{},;,etc.)Things you’ll learn in this assignment:
man 3 printf and K&R 7.2)man getlogin)man getenv)man console_codes and overview below)man string)The server at address comp211-2sp23.cs.unc.edu 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
login.cs.unc.eduwill not accept your logins due to “an ITS requirement for Onyen authentication.”
To access our server, you’ll use the ssh command as follows:
ssh ONYEN@comp211-2sp23.cs.unc.edu, where ONYEN is replaced with your Onyen.bash terminal on comp211-2sp23.cs.unc.edu. Congratulations!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:
The way to connect if you despise VPNs on principle:
ssh -J comp211@jetson-xavier.telenet.unc.edu ONYEN@comp211-2sp23.cs.unc.edu, where ONYEN is replaced with your Onyen.comp211@jetson-xavier.telenet.unc.edu's password: prompt, type the password listed on Sakai and press Enter.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, jetson-xavier.telenet.unc.edu, as a proxy for connecting to comp211-2sp23.cs.unc.edu. This research machine is a small embedded board, and may crash under high load (such as immediately before an assignment is due).
Key information:
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.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.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:

Want a break? Try running sl or cmatrix (press q to exit cmatrix).
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!
username@comp211-2sp23:~$
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
infocmpreference and add the secondary terminfo database path/usr/share/terminfo. The default manpage shown if you runman infocmpis in section3ncurses, 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 asgcc 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.
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.
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.
submit_a1 <path to your gdtbath.c file> on the course server, with the path to your implementation of gdtbath.c.File "<your file name>" uploaded., your submission is uploaded to Gradescope.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.