fork download
  1. #include<stdio.h>
  2. struct node
  3. {
  4. int item;
  5. struct node *link
  6. };
  7.  
  8. main()
  9. {
  10. struct node *start,*list;
  11. int i;
  12. start = (struct node *)malloc(sizeof(struct node));
  13.  
  14. list = start;
  15. start->link = NULL;
  16. for(i=0;i<5;i++)
  17. {
  18. list->item = i;
  19. list->link = (struct node *)malloc(sizeof(struct node));
  20. list = list->link;
  21.  
  22. }
  23.  
  24.  
  25. list->link = NULL;
  26. while(start != NULL)
  27. {
  28. if (start->link == NULL){
  29. break;
  30. }
  31. printf("%d\n",start->item);
  32. start = start->link;
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 2424KB
stdin
Standard input is empty
stdout
0
1
2
3
4