fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct XXX {
  6. struct XXX* next;
  7. int val;
  8. };
  9.  
  10. struct XXX* create(int val)
  11. {
  12. struct XXX* data;
  13. data = (struct XXX*) malloc(sizeof (struct XXX));
  14. data->next = NULL;
  15. data->val = val;
  16. return data;
  17. }
  18.  
  19. void add_last(struct XXX* data, int val)
  20. {
  21. while (data->next != NULL) {
  22. data = data->next;
  23. }
  24. data->next = create(val);
  25. }
  26.  
  27. int main(void)
  28. {
  29. struct XXX* data;
  30.  
  31. data = create(10);
  32. add_last(data, 20);
  33. add_last(data, 30);
  34. printf("%d, %d, %d\n", data->val, data->next->val, data->next->next->val);
  35. printf("0x%X\n", data);
  36. printf("0x%X\n", data->next);
  37. printf("0x%X\n", data->next->next);
  38. printf("0x%X\n", data->next->next->next);
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 1852KB
stdin
Standard input is empty
stdout
10, 20, 30
0x80C2008
0x80C2018
0x80C2028
0x0