Assignment 1 — The terminal, and your first C program
Move around a Linux filesystem and write down what you actually saw, then write, compile and break two small C programs — one that the compiler catches, and one it doesn’t.
Due Sep 2, 2026
This assignment comes in two parts. Part A uses only what we did on Thursday — you can finish it that evening. Part B uses the reading ([DIS] 16.1), which is due before Tuesday, and we will start it together in class on Tuesday. Do not wait for Tuesday to begin Part A.
You will hand in three files: hello.c, seconds.c, and notes.txt. Keep all three in one directory and work there all week.
The lab machines in Ben Franklin 103 are the guaranteed environment: everything here works there, and that is where I will assume you are. If you get a compiler working at home, good — but check your final files on a lab machine before you submit, and ask on Discord rather than improvising.
Submit early and submit again. Brightspace keeps the latest version, so upload a half-finished notes.txt on Friday and replace it on Tuesday. That costs you nothing and it means a machine that eats your files on Monday does not also eat your grade.
AI: the course AI policy applies in full. No AI-generated code, and no asking a chatbot to solve these problems before the deadline. The optional problems at the end say when that changes.
What the commands do
You are not expected to remember these. Keep this next to you while you work. The same card, plus a few things this one leaves out, is on the Linux command line quick reference — open it in a second tab.
pwd where am I Tab completes names — USE IT
ls what's here Up last command again
ls -a ...including hidden files Ctrl-C stop a runaway program
ls -l ...with sizes and dates clear tidy the screen
cd NAME go into NAME reset un-scramble the terminal
cd .. go up one
cd go home
mkdir NAME make a directory
nano FILE.c edit a file (^O Enter = save, ^X = quit; ^ means Control)
gcc FILE.c -o NAME compile (the program comes out as NAME)
./NAME run it (the ./ matters — ask me why if you missed it)
man ls shows you everything ls can do. Looking things up is not cheating; it is the skill.
If you want more than this while you work on Part A, [DIS] 17.1 covers the command line and the Unix filesystem, and 17.2 covers man itself. That whole chapter is a reference — look things up in it, do not try to read it through. It is not on the quiz.
Part A — the machine (after Thursday)
Make a place to work. Somewhere in your home directory, make a directory for this assignment and
cdinto it. Every file you write this week lives there.Write
hello.cfrom scratch. Not copied from a neighbour, not pasted from the web — type it. It must print a line containing your own name. Compile it withgcc hello.c -o hello, run it with./hello, and make sure the line appears.Draw the map, in words. Start
notes.txt(nano notes.txt) and answer these five. One or two lines each. Write down what you actually saw, not what you think should have happened.Type
cdwith no argument, thenpwd. What is the full path of your home directory?In your home directory, compare
lswithls -a. Roughly how many extra entries appear, name two of them, and say what their names have in common.Get to
/andlsit. Pick one directory there whose name means nothing to you, and write down what you guessed it holds.cd /homeandls. Whose account names are those? Now try tocdinto someone else’s andlsit. What happened, exactly?Using
ls -lin/usr/binor/etc, find a file older than you are. Give its name and its date.
Break
hello.con purpose, three times. Make each of these edits one at a time, recompile, and put the answers innotes.txt.Delete the semicolon at the end of the
printfline.Put the semicolon back; delete the
#include <stdio.h>line.Put it back; misspell
printfaspintf.
For each one, write down: the first line of what
gccsaid, copied as it appeared, and which line number it named compared with where the mistake actually was. Then, in one sentence: were all three the same kind of failure? One of them does not fail in the same place as the other two, and noticing that is the point of the exercise.Make sure
hello.cis back in working order before you submit it.
Part B — one number at the top (after the reading)
Write
seconds.c. The program declares a number of seconds as a variable at the top ofmain, and prints that duration broken into hours, minutes and seconds.10000 seconds is 2 h 46 m 40 sThe exact wording is yours. The requirement is this: there is exactly one number in the program that you change, and changing it to any other whole number must print a correct breakdown with no other edit. If you have to fix a second line to make it right, it is not done.
- Integer division and
%are the tools. [DIS] 16.1 covers both, including the thing that integer division does to the part after the decimal point. - Give the intermediate values names.
int hours = ...;reads; aprintfwith four operations inside it does not.
- Integer division and
Check it on the awkward numbers. Run it with
0,59,3600, and86399, and put the four output lines innotes.txt. At least one of them will look wrong or ugly to you. Say in one sentence which, and why.Now break it in a way the compiler does not catch. Add these two lines to
seconds.c, temporarily:printf("%d\n", 2.5); printf("%f\n", 10);Compile and run. Then compile it again as
gcc -Wall seconds.c -o secondsand look at what changes.In
notes.txt, write down: what those two lines printed, whethergccrefused to compile, whether-Wallchanged its mind, and — in two or three sentences — how this failure is different from the missing semicolon in step 4a.This is the most important paragraph you will write this week. Take it seriously.
Then delete the two lines, so the program you submit does what step 5 says.
Submit
hello.c,seconds.candnotes.txton Brightspace. Three files. Compile both programs one last time on a lab machine before you upload — a file that does not compile gets no credit for the parts that would have worked.
Grading
Full credit for two programs that compile and run, and a notes.txt that answers 3, 4, 6 and 7.
Two things carry most of the weight, because they are the point of the assignment:
- Step 5 — one number at the top, and the whole breakdown follows from it.
- Step 7 — your own account of the difference between a program the compiler rejects and a program it accepts and runs wrong.
Answers in notes.txt are graded on being honest about what you saw, not on being right. “It printed nothing and I don’t know why” is worth more than a confident description of something that did not happen.
Presentation
One of you will be asked on Thursday, September 3 to put your files on the projector and walk the class through them — what the compiler said, and what step 7 printed. You will not be told in advance. There are ten of us and about twelve assignments over the term, so plan on presenting about once — twice at the most; a solution that does not compile is not an excuse. See the syllabus on how presentation is graded.
What else to do (optional part)
Ungraded. No points, and skipping them costs nothing.
Compile with
gcc hello.cand no-oat all. Something still appears — find it withlsand run it. What is it called, and why do you suppose that is the default?Right after
./seconds, typeecho $?. Then changereturn 0;toreturn 3;, recompile, and do it again. Write one line about whatint mainwas for all along.Open
man lsand find a flag we did not use in class that does something you would actually want. Write down the flag and what it does. (qquits the manual.)After the deadline has passed — and only then, per the AI policy — ask a chatbot to write
seconds.cfor you. Does it compile? Does it hold up to step 5, where you change the one number at the top? Write one line saying what it did differently from you, and whether you think that was better.