CS-211 Fall 2015 Lab 2 Calling Functions

Getting Started

After you have logged on to one of the Linux Lab machines, open a terminal window like you did last week. (Go back to last week's lab if you forgot how.) Then, make a lab2 subdirectory of your home directory. Download graph.c and move it into you lab2 directory. (Note... in some browsers, you may need to right click on the graph.c hyperlink, and choose the Save Link As... option in order to download)

Compiling and Running graph.c

Make lab2 your current directory, and edit the graph.c code using the command gedit graph.c&, like we learned last week. Browse through the code. Notice that there are five functions defined already... constant, linear, quadratic, graphFn, and main.

Once you have browsed through the code, go back to your terminal window, and compile the code using the command gcc -g -o draw graph.c. Unless you have changed something, the code should compile with no warnings or errors.

Once the code is compiled, try running it. Start out running with no parameters using ./draw. You should get a message telling you that you need a parameter. Try again with ./draw C. You should now see a graph of a constant function on your screen. You may have to scroll up to see the top of this graph. Try ./draw L to see a linear graph.

Making Some Changes

Now, let's start changing the code in graph.c. Go to the edit window.

If you are surprised by any of these results, you may want to debug the code. To run under the debugger, use the commmand gdb draw. Then, set breakpoints on the line or lines you want to stop by typing (for instance) break 7 at the (gdb) prompt to break at line 7 in your code. Then use the (gdb) sub-command run L (or run C or run Q) to start the process and get to the first breakpoint.

Lab Report

Download and edit the following file: lab2_report.txt. Then submit your editted file on Blackboard under the main CS-211 class page (not the lab section page), under "Contents" in the Lab_02 report area.