listen.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //type dfinitions
  4. typedef struct lin_list
  5. {
  6. char *value;
  7. struct lin_list *next;
  8. }LinListCell, *LinList_p;
  9. //function derfinitions
  10. LinList_p LinListAllocCell(char* value);
  11. void LinListFreeCell(LinList_p junk);
  12. void LinListFree(LinList_p *junk);
  13. LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell);
  14. int main(void)
  15. {
  16. printf("blaa\n");
  17. LinList_p anchor = LinListAllocCell("xx");
  18. anchor->next = LinListAllocCell("xc");
  19. printf("anchor=%p\n",anchor);
  20. printf("%p %p \n", anchor->value,anchor->next->value);
  21. }
  22. LinList_p LinListInsertFirst(LinList_p anchor,LinList_p newCell)
  23. {
  24. LinListCell *buff = anchor;
  25. anchor = LinListAllocCell("");
  26. anchor->next = buff;
  27. }
  28. LinList_p LinListAllocCell(char* value)
  29. {
  30. LinList_p newcell = malloc(sizeof(LinListCell));
  31. newcell->next = NULL;
  32. newcell->value = strdup(value);
  33. return newcell;
  34. }
  35. void LinListFreeCell(LinList_p junk)
  36. {
  37. free(junk);
  38. }
  39. void LinListFree(LinList_p *junk)
  40. {
  41. LinListCell *next = junk;
  42. LinListCell *buff;
  43. *junk = NULL;
  44. while(next != NULL)
  45. {
  46. buff = next->next;
  47. free(next);
  48. }
  49. }