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...


linux1[10]% gcc -ansi -Wall -c lab12.c lab12.c: In function 'main': lab12.c:40: warning: unused variable 'head' lab12.c:37: warning: unused variable 'i' lab12.c:36: warning: unused variable 'id' lab12.c: In function 'ReadFile': lab12.c:119: warning: unused variable 'taName' lab12.c:118: warning: unused variable 'tempNode' lab12.c:117: warning: unused variable 'tempStudent' linux1[11]% gcc lab12.o linkedlist.o linux1[12]% a.out data.txt Welcome to the last lab of the semester! :) linux1[13]%