Step 1


Recall that we learned in Lab 11 that as your projects begin to get more complicated and require multiple files, avoiding a soupy mess of #includes may become much more difficult. As programs grow in complexity, it becomes necessary to guard header files against multiple inclusion -- which is what happens when somehow, the same file is included in main twice by two different things.

Put the following lines of code at the beginning of linkedlist.h:

#ifndef LINKEDLIST_H #define LINKEDLIST_H

and put the following line of code at the very end of linkedlist.h:

#endif

Then go ahead and compile, link, and run the code.

What this code is basically saying is: "If LINKEDLIST_H (linkedlist.h) isn't defined, define it!" This will protect your code against multiple inclusions. For future courses, you'll be expected to guard each and every header file. It's just a good habit to get into.

You may now continue to Step 2...


Linux[1]% gcc -Wall -ansi -c lab12.c lab12.c: In function `main': lab12.c:33: warning: unused variable `tempStudent' lab12.c:34: warning: unused variable `tempNode' lab12.c:35: warning: unused variable 'id' lab12.c:39: warning: unused variable `head' Linux[2]% gcc -Wall -ansi -c linkedlist.c Linux[3]% gcc lab12.o linkedlist.o Linux[4]% a.out Not enough command line arguments! Use a.out <filename> Linux[5]% a.out data File data could not be opened! Linux[6]% a.out data.txt Welcome to the last lab of the semester! :)