Discussion 6 HW4 and Libraries
Let s talk Assignment 4 Builds on Assignment 3 concepts
Let s talk Assignment 4 Builds on Assignment 3 concepts Now, you have to build a glossary.
Pointer to pointer int** x; int* y = (int*)malloc(sizeof int); x=&y;
Explanation of search() struct WordSet { int size; *head;
Explanation of search() struct { int freq; char *word; ; struct WordSet { int size; *head;
Explanation of search() Start 2 by 3 possible 1 NULL *head p WordSet struct { int freq; char *word; ; struct WordSet { int size; *head;
Explanation of search() Start 2 by 3 possible 1 NULL p *head WordSet struct { int freq; char *word; ; struct WordSet { int size; *head;
Explanation of search() Start 2 by 3 possible 1 NULL p *head WordSet struct { int freq; char *word; ; struct WordSet { int size; *head;
Explanation of search() Start 2 by 3 possible 1 NULL p *head WordSet struct { int freq; char *word; ; struct WordSet { int size; *head;
Explanation of search() Start 2 by 3 possible 1 NULL p *head WordSet struct { int freq; char *word; ; struct WordSet { int size; *head;
i-clicker question Suppose p points to a pointer to a, how do we access the s word? A. p->word B. (*p)->word C. (**p)->word struct { int freq; char *word; ;
i-clicker question Suppose p points to a pointer to a, how do we access the word of the s immediate successor? A. (*((*p)->next)).word B. ((*p)->next).word C. ((*p)->next)->word D. (*((*p)->next))->word struct { int freq; char *word; ;
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode Reached the end of linked list
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode Reached the end of linked list
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode Reached the end of linked list Can be used for adding and removing a Add: let *return points to the newly created node if a maching wordnode is not found
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode Reached the end of linked list Can be used for adding and removing a Add: let *return points to the newly created node if a maching wordnode is not found Remove: let *return points to the next node of the given word node s immediate successor if a matching wordnode is found
Return value of search static **search (WordSet *wset, char *word) { found a matching wordnode Reached the end of linked list Can be used for adding and removing a Add: let *return points to the newly created node if a maching wordnode is not found Remove: let *return points to the next node of the given word node s immediate successor if a matching wordnode is found Fast Add: first remove, then add at the beginning
Two loops words_next_word
words_next_word Two loops Skip over leading non-alphanumeric characters Isalnum: <ctype.h>
words_next_word Two loops Skip over leading non-alphanumeric characters Isalnum: <ctype.h> Store all alphanumeric characters into buf before calling make_string Do I call make_string with an empty buffer? Do I need to null-terminate in buf?
words_next_word Two loops Skip over leading non-alphanumeric characters Isalnum: <ctype.h> Store all alphanumeric characters into buf before calling make_string Do I call make_string with an empty buffer? Do I need to null-terminate in buf? Use getchar() to read more characters
words_next_word Two loops Skip over leading non-alphanumeric characters Isalnum: <ctype.h> Store all alphanumeric characters into buf before calling make_string Do I call make_string with an empty buffer? Do I need to null-terminate in buf? Use getchar() to read more characters Hand simulate the function on various cases
Wset_free Free nodes in the linked list Free the word set
Group Activity What is linking? What is the purpose of linking? Could you compare static linking and dynamic linking? Suppose foo.c calls functions in libx.a; libx.a calls functions in liby.a; liby.a calls functions in libx.a; libx.a calls functions in foo.c. What is the gcc command line that will allow the static linker to resolve all symbol references? What is the difference between a definition and a declaration? When do we use extern?