[prev] [index] [next]

Tips for Next Week's Lab


Memory management, Linked lists

  • Concatenate all command line arguments into a string on the heap
    • allocate sufficient space using malloc()
    • always cast the result of malloc()

      char *heap = (char *)malloc( ... )
      

    • always free memory to avoid memory leaks

      free(heap);
      

  • Same tips apply to heapsum.c
  • Linked lists
    • understand and use functions from lecture

      NodeT *makeNode(int value);
      freeList(NodeT *head);
      NodeT *insertTail(NodeT *head, int value);
      

    • modify function from lecture

      void printList(NodeT *head);
      

      sample output: 10->20->30->40