CS140 Lab 6 - C Programming Refresher
Objective
- Refresh (or learn for the first time) some details needed in C
- Pointers, Memory addresses, structs, dynamic memory
|
Background
Tutorial Tasks
- Start with the Lab-Tutorial document here.
Program the examples. Create the makefile and compile with make. Do the very brief gdb tutorial.
- Next, spend some time with Kernighan's C tutorial (linked above). Experiment with anything you don't already know well.
Pay special attention to sections 17-20.
|
Programming Tasks
- Create a program with the structure defined in Kernighan's tutorial section 20.
- Add to the show_bytes.c some code
to display the bytes of the struct.
- Load a stuct variable with some data (that you can predict what it looks like) and use show_bytes to verify
that it does what you expect.
- Print out the size in bytes of the struct.
- Print out the memory address of the struct and each of it's data members.
- Print out the memory offset of each of the data members of the struct.
- Create an array of structs using
malloc
Linked Lists:
- Create a struct to act as a linked list node that holds integers.
- Write utility method to
malloc nodes
- Write methods to add/remove nodes from the head, find the length of a list, and iterate through a list printing out each value.
|
Check out
When you are done with the lab exercises, check out with the instructor or the TA.