fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. typedef struct schedule{
  5. struct schedule *next;
  6. int day;
  7. //int hasNext;
  8. char title[100];
  9. }SCHEDULE;
  10.  
  11. SCHEDULE *now,*sch;
  12.  
  13. int main(){
  14. sch = 0;
  15. now = sch;
  16. int continuebool=1;
  17. while(continuebool)
  18. {
  19. int wkday = 0;
  20. printf("\nType day(int):");
  21. scanf("%d",&wkday);
  22. if(wkday == 0)
  23. {
  24. continuebool = 0;
  25. }
  26. else
  27. {
  28. SCHEDULE *wk = (SCHEDULE*)malloc(sizeof(SCHEDULE));
  29. wk->day = wkday;
  30. wk->next = 0;
  31. printf("\nType title(char*):");
  32. scanf("%s",wk->title);
  33. if(sch == 0)
  34. {
  35. sch = wk;
  36. now = sch;
  37. }
  38. else
  39. {
  40. now->next = wk;
  41. now = wk;
  42. }
  43. }
  44. }
  45. now = sch;
  46. while(now)
  47. {
  48. printf("\nday:%d\n",now->day);
  49. printf("title:%s\n",now->title);
  50. SCHEDULE *old = now;
  51. now = now->next;
  52. if(old != 0) free(old);
  53. }
  54. scanf("%d");
  55. return 0;
  56. }
Success #stdin #stdout 0.02s 1856KB
stdin
1011
test1
1231
test2
0
stdout
Type day(int):
Type title(char*):
Type day(int):
Type title(char*):
Type day(int):
day:1011
title:test1

day:1231
title:test2