Learn › Learn C › C Foundations
gcc - a hands-on Linux lab on a real virtual machine.
Read 3 integers from argv, print and return the max as the exit code.
Six lessons are behind you: the toolchain, types, control flow, functions, and pointers. This lab is where you write a complete program with no scaffolding. The goal is small and sharp: take three integers from the command line, find the largest, and report it two ways at once.
The contract. Your program runs as ./solution A B C with exactly three integer arguments. Print the maximum to stdout as a single line, then return that same number as the exit code, the value a script reads with $?. If the argument count is wrong, an argument missing or an extra one given, print a usage line to stderr and exit 64, the conventional code for a command line usage error. Convert the arguments with atoi(); the grader only sends well formed integers.
One caveat worth knowing before you start: exit codes on Linux are a single byte, 0 to 255. That is why every test keeps the maximum between 0 and 120, so the number you print and the code you return always match. Some of the arguments are negative, but the maximum never is.
Two classic wrong turns to avoid. First, argv holds strings, not numbers, so comparing before converting gives string order, where "9" beats "120". Second, remember from the Hello, machine lesson that argv[0] is the program name: with three arguments, argc is 4 and your numbers live in argv[1] through argv[3].
TEST compiles your code and runs the two visible sample tests, as many times as you like. ATTEMPT runs the full hidden suite: negatives, duplicates, all equal, the top of the range, and bad argument counts. Pass every hidden test and the lab completes.
Practice Lab: Max of Three in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.