/**Function********************************************************************

  Synopsis           Frees the given list node and the associated book

  SideEffects        Frees the given list node and the associated book

******************************************************************************/
void free_list_node(struct book_node *node)
{
	if (node != NULL)
	{
		free_book(node->book);
		free(node);
	}
}
Example #2
0
int main() {

  struct link **book;
  
  book = new_book();
  book = add_entry(book, "Eddie", "*****@*****.**");
  book = add_entry(book, "Ed", "*****@*****.**");
  book = add_entry(book, "HughJazz", "*****@*****.**");
  book = add_entry(book, "SeymorButz", "*****@*****.**");
  book = add_entry(book, "Fry", "*****@*****.**");
  book = add_entry(book, "Bender", "*****@*****.**");

  //OPEN FILE
  int fd = open("book.dat",  O_CREAT | O_RDWR, 0644);

  //WRITE TO FILE

  int b;
  char n[256];
  char e[256];
  int a;
  struct link *p;
  p = (struct link *)malloc(sizeof(struct link));
  for (a=0; a<26; a++){
    p = book[a];
    while(p){
      strncpy(n, return_name(p), 256);
      strncpy(e, return_email(p), 256);
      b = write(fd, n, 256);
      b = write(fd, e, 256);
      p = p->next;
    }
  }

  book = free_book( book );
  free(book);
 
  return 0;
}