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. int main(){
  12. SCHEDULE *now,*sch=(SCHEDULE*)malloc(sizeof(SCHEDULE));
  13. int continuebool=1;
  14. now=sch;
  15.  
  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. if(continuebool){
  21. now->hasNext =1;
  22. now->next =(SCHEDULE*)malloc(sizeof(SCHEDULE));
  23. now =now->next;
  24. }
  25. now->hasNext=0;
  26. }
  27.  
  28. while(sch->hasNext){
  29. printf("\nday:%d\n",now->day);
  30. printf("title:%s\n",now->title);
  31. sch=sch->next;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 1856KB
stdin
1011
test
1
1231
test2
0
stdout
Type day(int):
Type title(char*):
continue(1/0):
Type day(int):
Type title(char*):
continue(1/0):
day:1231
title:test2