fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct user user;
  4. typedef struct message message;
  5. struct message
  6. {
  7. int id;
  8. int user;
  9. message *next;
  10. message *firstm;
  11. };
  12.  
  13. struct user
  14. {
  15. char name[10];
  16. int id;
  17. message *messages;
  18. user *next;
  19. };
  20.  
  21. int main(void) {
  22. user users[4] = {
  23. {.name = {0} }
  24. };
  25. message msgs[4] = {{0}};
  26.  
  27. for (int i = 0; i < 4; i++) {
  28. msgs[i].firstm = &msgs[0];
  29. msgs[i].next = &msgs[i+1];
  30. msgs[i].id = i;
  31. users[i].messages = &msgs[0];
  32. users[i].next = &users[i+1];
  33. }
  34. msgs[4].next = NULL;
  35. users[4].next = NULL;
  36.  
  37.  
  38. user *temp = &users[0];
  39. for (message *firstme = temp->messages->firstm;
  40. firstme->next != NULL;
  41. firstme = firstme->next) {
  42. printf("%d \n", firstme->id );
  43. }
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
0 
1 
2 
3