fork(1) download
  1. #include <stdio.h>
  2.  
  3. struct entry
  4. {
  5. int value;
  6. struct entry * next;
  7. };
  8.  
  9. int main()
  10. {
  11. void insertEntry(struct entry * list_pointer, struct entry * prev);
  12. struct entry *list_pointer, *prev;
  13. struct entry n1, n2, n3, n4;
  14. n1.value = 100;
  15. n1.next = &n2;
  16. n2.value = 200;
  17. n2.next = &n3;
  18. n3.value = 300;
  19. n3.next = &n4;
  20. n4.value = 400;
  21. n4.next = (struct entry *) 0;
  22. list_pointer = &n1;
  23. prev = &n2;
  24.  
  25. printf("Before: \n");
  26.  
  27. while (list_pointer != (struct entry *) 0) {
  28. printf("%i \n", list_pointer->value);
  29. list_pointer = list_pointer->next;
  30. }
  31. insertEntry(list_pointer, prev);
  32. printf("After: \n");
  33. list_pointer = &n1;
  34. while (list_pointer != (struct entry *) 0) {
  35. printf("%i\n", list_pointer->value);
  36. list_pointer = list_pointer->next;
  37. }
  38. return 0;
  39. }
  40.  
  41. void insertEntry(struct entry * list_pointer, struct entry * prev)
  42. {
  43. struct entry newEntry;
  44. newEntry.value = 555;
  45. printf("TEST 1\n");
  46. while (list_pointer != (struct entry *) 0) {
  47.  
  48. if (list_pointer == prev) {
  49. printf("TEST 2\n");
  50. newEntry.next = list_pointer;
  51. list_pointer->next = &newEntry;
  52. }
  53. else
  54. list_pointer = list_pointer->next;
  55. printf("TEST 3\n");
  56. }
  57. }
  58.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
Before: 
100 
200 
300 
400 
TEST 1
After: 
100
200
300
400