0% found this document useful (0 votes)
3 views4 pages

Weekly Calendar Activity Tracker

The document outlines a C program for managing a weekly calendar using a structure called CalendarDay. It includes functions to create, read, display, and clean up calendar entries for seven days, allowing users to input day names, dates, and activities. Memory management is handled using dynamic allocation and deallocation to ensure efficient use of resources.

Uploaded by

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

Weekly Calendar Activity Tracker

The document outlines a C program for managing a weekly calendar using a structure called CalendarDay. It includes functions to create, read, display, and clean up calendar entries for seven days, allowing users to input day names, dates, and activities. Memory management is handled using dynamic allocation and deallocation to ensure efficient use of resources.

Uploaded by

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

DATA STRUCTURES LABORATORY BCSL305

#include <stdio.h>
#include <stdlib.h>
struct CalendarDay
{
char *dayName;
int day;
int month;
int year;
char *activity;
};
void create(struct CalendarDay calendar[7])
{
for(int i=0;i<7;i++)
{
calendar[i].dayName=(char *)malloc(20);
calendar[i].activity=(char *)malloc(100);
}
}
void read(struct CalendarDay calendar[7])
{
for(int i=0;i<7;i++)
{
printf("Enter day name for Day %d: ",i+1);
scanf("%s",calendar[i].dayName);
printf("Enter date for Day %d (dd/mm/yyyy): ",i+1);

Dept. of AI & DS Page 1


DATA STRUCTURES LABORATORY BCSL305
scanf("%d/%d/%d",&calendar[i].day,&calendar[i].month,&calendar[i].year);
printf("Enter activity for Day %d: ",i+1);
scanf(" %[^\n]",calendar[i].activity);
}
}
void display(struct CalendarDay calendar[7])
{
printf("\nActivity Details for the Week:\n");
for(int i=0;i<7;i++)
{
printf("Day Name: %s\n",calendar[i].dayName);
printf("Date: %02d/%02d/%4d\n",calendar[i].day,calendar[i].month,calendar[i].year);
printf("Activity: %s\n\n",calendar[i].activity);
}
}
void cleanup(struct CalendarDay calendar[7])
{
for(int i=0;i<7;i++)
{
free(calendar[i].dayName);
free(calendar[i].activity);
}
}
int main()
{
struct CalendarDay calendar[7];

Dept. of AI & DS Page 2


DATA STRUCTURES LABORATORY BCSL305
create(calendar);
read(calendar);
display(calendar);
cleanup(calendar);
return 0;
}

Dept. of AI & DS Page 3


DATA STRUCTURES LABORATORY BCSL305

Dept. of AI & DS Page 4

You might also like