- Exercises - exercises to go with the labs and lectures
- Your computer’s filesystem
- IDEs, Code editors, and using SFTP to edit remote files locally
- Multi-file development
To get the examples on your own computer, right-click and save to download them.
To get the examples on thoth:
- Right-click on the example link, and click “Copy link” or equivalent
- On thoth, make sure you are in the directory that you want to put the example
- On thoth, type
wget, a space, then paste the link, and hit enter
thoth will download the file from this site directly.
Safari users: Safari sometimes changes file extensions. Do not trust it.
|Intro and C Basics
|Welcome to C!
|You're not in Java-land anymore.
|Animation of 1_cant_add_strings
|Step through with "Next >". Watch str = str + x especially.
|"Fun" things can happen when you don't initialize variables.
|Printing things out with C's version of System.out.println.
|Getting input with fgets... kinda.
|Coming up with the signature for a function that takes an array parameter.
|The proper way to write the get_line function.
|Using a function prototype to access a function before it's defined.
|Returning local arrays is a bad idea.
|sizeof() might not work how you expect.
|Shows the address-of &x and value-at *p operators to create and access pointers.
|Yep. Shows array address calculation.
|Double-pointers are usually used for arrays-of-arrays. Like arrays of strings!
|2D arrays and arrays-of-arrays are actually different things!
|The const keyword is a neat addition to pointers.
|Pointer casting lets you "reinterpret" the meaning of bit patterns.
|Animation of 6_ptr_casts
|(Click "Visualize Execution") You can step through it line-by-line and see what's happening.
|Shows addresses of local variables inside ARs as functions are called.
|Strings in C are bad, okay?
|String literals are different beasts.
|strlen() and sizeof() are very different things.
|Reading/writing text files is pretty straightforward.
|Reading/writing binary files is also pretty straightforward.
|The heap (malloc/free)
|(Click "Visualize Execution") Very basic linked list on the heap.
|Use valgrind to see the memory this program leaks.
|(Click "Visualize Execution") after freeing heap memory, it's invalid.
|Structs, Enums, Typedefs
|How to define and use a simple struct.
|Making self-referential struct pointers.
|Common patterns for using enums.
|Command-line arguments, like you'll need for proj1!
|Here's exactly how NOT to write a function. Thanks, MARS.
|Pseudocode improvement of the previous function.
|A program that crashes. Use the debugger to figure out why!
|Multi-file compilation and make
|A very simple compilation script. You'll have to chmod +x it to use it.
|The makefile for the following example. IMPORTANT: make sure its name is Makefile exactly.
|The main file.
|The second file.
|The header file for 11_user.c.
|Linking and Loading
|Goes with the next file.
|Goes with the previous file.