1 / 7

CSC 253

CSC 253. Lecture 13. Syntax. In the lecture, Jason defined a typedef typedef struct addrEntry { char* name; … struct addrEntry *next; } AddrT, *AddrTP What is the purpose of the last line? To declare two addrEntry structures To declare two synonyms for the same type

Download Presentation

CSC 253

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 253 Lecture 13

  2. Syntax • In the lecture, Jason defined a typedef • typedef struct addrEntry { char* name;… struct addrEntry *next;} AddrT, *AddrTP • What is the purpose of the last line? • To declare two addrEntry structures • To declare two synonyms for the same type • To declare synonyms for two slightly different types • To assign the same value to two different variables

  3. Consider the main program … • int main(){ AddrT myAddressList=createBlank(); AddrT temp=createBlank(); myAddressList.next=&temp; printAddr(&myAddressList); deleteAddr(temp); myAddressList.next=NULL; deleteAddr(myAddressList);} • What is the code doing? • Creating two address nodes and linking them together • Creating two address nodes that are not linked together • Creating one address node that is known by two names

  4. Let’s read values into our nodes … • In the following code, … char1 readLine(FILE2 file) { int i; char3 line; if ((line = malloc(256*sizeof(char))) == NULL) return EXIT_FAILURE; return fgets(line4, 256, file5);} • where should there be asterisks? • Locations 1, 2, and 3 • Locations 1 and 3 • Locations 1 and 2 • Locations 1, 2, 3, and 4 • Locations 1, 2, 3, 4, and 5

  5. Let’s run the code & read in values • How do we call this function from the main program? • When we run the program, what will be the ID numbers of the two nodes? • Why is there a blank line between every two lines of output?

  6. Let’s make the code for printing less repetitive • Define a printField(…) function. • How many places can we call it?

  7. Field-referencing notation • Which of the following mean the same thing as myAddress->name? • myAddress.name • *myAddress.name • (*myAddress).name • b and c • None of the above

More Related