fork download
  1. #include "stdio.h"
  2. #include "malloc.h"
  3.  
  4.  
  5. struct rib
  6. {
  7. int from;
  8. int to;
  9. int weight;
  10. };
  11.  
  12. int main(int argc, char const *argv[])
  13. {
  14. struct rib *incidental;
  15.  
  16. for (int i = 0; i < 12; ++i)
  17. {
  18. incidental = NULL;
  19. for (int j = 0; j < 3; ++j)
  20. {
  21. printf("ok %i\n", j);
  22. incidental = (struct rib*)realloc(incidental, (j+1)*sizeof(struct rib));
  23. if (incidental == NULL)
  24. {
  25. printf("NULL YOU are fool!!!!!!\n");
  26. }
  27. incidental[j].from = j+1;
  28. incidental[j].to = (j+1)*2;
  29. incidental[j].weight = (j+1)*4;
  30. }
  31.  
  32. for (int k = 0; k < 3; ++k)
  33. {
  34. printf(" %i-%i=%i\n", incidental[k].from, incidental[k].to, incidental[k].weight);
  35. }
  36. }
  37.  
  38.  
  39. }
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12
ok 0
ok 1
ok 2
 1-2=4
 2-4=8
 3-6=12