fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef struct schedule {
  5. int day;
  6. char title[100];
  7. struct schedule *next;
  8. } SCHEDULE;
  9.  
  10. int main(void) {
  11. int continuebool;
  12. SCHEDULE *now, *sch;
  13.  
  14. sch = malloc(sizeof *sch);
  15. now = sch;
  16. while (continuebool) {
  17. printf("\nType day(int):"); scanf("%d", &now->day);
  18. printf("\nType title(char*):"); scanf("%s", now->title);
  19. printf("\ncontinue(1/0):"); scanf("%d", &continuebool);
  20.  
  21. if(continuebool){
  22. now->next = malloc(sizeof *now->next);
  23. now = now->next;
  24. }
  25. }
  26.  
  27. for (now = sch; now; now = now->next) {
  28. printf("\nday:%d\n", now->day);
  29. printf("title:%s\n", now->title);
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 1812KB
stdin
1
foo
1
2
bar
0
stdout
Type day(int):
Type title(char*):
continue(1/0):
Type day(int):
Type title(char*):
continue(1/0):
day:1
title:foo

day:2
title:bar