70 likes | 208 Vues
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
E N D
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 • To declare synonyms for two slightly different types • To assign the same value to two different variables
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
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
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?
Let’s make the code for printing less repetitive • Define a printField(…) function. • How many places can we call it?
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