fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. struct Day
  6. {
  7. char*name;
  8. int date;
  9. char*activity;
  10. };
  11.  
  12. int main()
  13. {
  14. struct Day calendar[7];
  15. for(int i=0;i<7;i++)
  16. {
  17. calendar[i].name=(char*)malloc(50*sizeof(char));
  18. calendar[i].activity=(char*)malloc(100*sizeof(char));
  19. printf("enter the name of day %d:",i+1);
  20. scanf("%s",calendar[i].name);
  21. printf("enter the date of day %d:",i+1);
  22. scanf(" %d",&calendar[i].date);
  23. printf("enter the activity of day %d:",i+1);
  24. scanf("%[^\n]s",calendar[i].activity);
  25.  
  26. }
  27. printf("calendar for the week:\n");
  28. for(int i=0;i<7;i++)
  29. {
  30. printf("day:%s\n",calendar[i].name);
  31. printf("date:%d\n",calendar[i].date);
  32. printf("activity:%s\n\n",calendar[i].activity);
  33. }
  34. for(int i=0;i<7;i++)
  35. {
  36. free(calendar[i].name);
  37. free(calendar[i].activity);
  38. }
  39. return 0;
  40. }
  41.  
  42.  
  43.  
Success #stdin #stdout 0s 5284KB
stdin
45
stdout
enter the name of day 1:enter the date of day 1:enter the activity of day 1:enter the name of day 2:enter the date of day 2:enter the activity of day 2:enter the name of day 3:enter the date of day 3:enter the activity of day 3:enter the name of day 4:enter the date of day 4:enter the activity of day 4:enter the name of day 5:enter the date of day 5:enter the activity of day 5:enter the name of day 6:enter the date of day 6:enter the activity of day 6:enter the name of day 7:enter the date of day 7:enter the activity of day 7:calendar for the week:
day:45
date:0
activity:

day:
date:585061072
activity:

day:
date:0
activity:

day:
date:0
activity:

day:
date:15774463
activity:

day:
date:1
activity:

day:
date:1169015653
activity: