fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct Time{
  6. char name[30];
  7. int pnts;
  8. int vit, emp, der;
  9. int gf, gt;
  10.  
  11. struct Time *next;
  12. struct Time *prev;
  13. } time;
  14.  
  15. typedef struct campeonato { time *first; } campeonato;
  16.  
  17. void addTime(campeonato *c, char name[]) {
  18. time *t = malloc(sizeof(time));
  19. strcpy(t->name, name);
  20. t->next = NULL;
  21. t->pnts = t->vit = t->emp = t->der = t->gt = t->gf = 0;
  22. if (c->first == NULL) {
  23. c->first = t;
  24. t->prev = NULL;
  25. } else {
  26. time *p = c->first;
  27. while (p->next != NULL) {
  28. p = p->next;
  29. }
  30. p->next = t;
  31. t->prev = p;
  32. }
  33. }
  34.  
  35. int main(void) {
  36. campeonato c = { .first = NULL };
  37. addTime(&c, "Santos");
  38. time *t = c.first;
  39. printf("%s", t->name);
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
Santos