0% found this document useful (0 votes)
7 views2 pages

Program 1

Uploaded by

Shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Program 1

Uploaded by

Shreyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <stdlib.h>

struct Day {
char *dayName;
int date;
char *activity;
};

void create(struct Day *day) {


day->dayName = (char *)malloc(sizeof(char) * 20);
day->activity = (char *)malloc(sizeof(char) * 100);
printf("Enter the day name: ");
scanf("%s", day->dayName);
printf("Enter the date: ");
scanf("%d", &day->date);
printf("Enter the activity plan for the day: ");
scanf("%s", day->activity);
}

void read(struct Day *calendar, int size) {


for (int i = 0; i < size; i++) {
printf(“Enter the activity for day %d”,i+1);
create(&calendar[i]);
}
}

void display(struct Day *calendar, int size) {


printf("\nWeek's Activity Details:\n");
for (int i = 0; i < size; i++) {
printf("Day %d:\n", i + 1);
printf("Day Name: %s\n", calendar[i].dayName);
printf("Date: %d\n", calendar[i].date);
printf("Activity: %s\n", calendar[i].activity);
}
}

void freeMemory(struct Day *calendar, int size) {


for (int i = 0; i < size; i++) {
free(calendar[i].dayName);
free(calendar[i].activity);
}
free(calendar);
}

int main() {
struct Day *calendar;
int size;
printf("Enter the number of days in week: ");
scanf("%d", &size);

calendar = (struct Day *)malloc(size * sizeof(struct Day));

if (calendar == NULL) {
printf("Memory allocation failed. Exiting program.\n");
return 1;
}

read(calendar, size);
display(calendar, size);
freeMemory(calendar, size);

return 0;
}

You might also like