meeting *del_meeting(meeting *detailes,int *cptr,int which)
{
meeting *ptr=NULL;
int i;
if(*cptr==1)
{
free(detailes);
(*cptr)--;
return ptr;
}
ptr=detailes;
detailes=(meeting*)malloc( sizeof(meeting) * (*cptr-1) );
if(detailes==NULL)
{
puts("Error in memory allocation.");
exit(1);
}
for(i=0;i<which;i++)
detailes=ptr;
for(i=which;i<(*cptr);i++)
detailes=ptr[i+1];
(*cptr)--;
free(ptr);
return detailes;
}
void print_meeting(meeting *meet)
{
printf("\nDate : ");
puts(meet->date);
printf("\nDescription : ");
puts(meet->description);
printf("\nTime : ");
puts(meet->time);
printf("\nNotes : ");
puts(meet->notes);
}
int main_menu()
{
int choose=0;
do
{
printf("\nPlease Choose one of the following\n");
printf("1. Add Meeting\n");
printf("2. Delete Meeting\n");
printf("3. Update Meeting\n");
printf("4. See all of my Meetings\n");
printf("5. Exit\n");
scanf("%d",&choose);
if(choose==5)
exit(0);
}while(choose!=1 && choose!=2 && choose!=3 && choose!=4);
return choose;
}
int update_meeting_menu()
{
int choose=0;
do
{
printf("\nWhat whould you like to update in this meeting?");
printf("\n1. date");
printf("\n2. description");
printf("\n3. time");
printf("\n4. notes");
printf("\n5. nothing - EXIT");
scanf("%d",&choose);
if(choose==5)
break;
}while(choose!=1 && choose!=2 && choose!=3 && choose!=4);
return choose;
}
void update_meeting(meeting *meet,int who,int what)
{
char temp[20];
meeting *temptr;
temptr=meet+who;
switch(what)
{
case 1://date
printf("\nEnter new Date : ");
flushall();
gets(temp);
strcpy(temptr->date,temp);
break;
case 2://description
printf("\nEnter new Description : ");
flushall();
gets(temp);
strcpy(temptr->description,temp);
break;
case 3://time
printf("\nEnter new Time : ");
flushall();
gets(temp);
strcpy(temptr->time,temp);
break;
case 4://notes
printf("\nEnter new Time : ");
flushall();
gets(temp);
strcpy(temptr->notes,temp);
break;
}
}
void main()
{
meeting *meetptr=NULL;
int i,choose,counter=0,who,what;
printf("=== welcome yada yada ===\n");
do{
choose=main_menu();
switch(choose)
{
case 1://add
meetptr=add_meeting(meetptr,&cou nter);
break;
case 2://delete
if(counter>0)
{
for(i=0;i<counter;i++)
{
printf("\n=== Meeting no %d ===\n",i);
print_meeting(&meetp tr);
}
printf("Choose Meeting to delete\n");
scanf("%d",&who);
meetptr=del_meeting(meetptr,&a mp;counter,who);
break;
}
printf("\n=== Nothing to delete ===\n");
break;
case 3://update
if(counter>0)
{
for(i=0;i<counter;i++)
{
printf("\n=== Meeting no %d ===",i);
print_meeting(&meetp tr);
}
printf("Choose Meeting to Update:\n");
scanf("%d",&who);
printf("Which field whould you like to Update?\n");
what=update_meeting_menu();
if(what==5)
break;
update_meeting(meetptr,who,wha t);
break;
}
printf("\n=== Nothing to Update ===\n");
break;
case 4://print all data
if(counter>0)
{
for(i=0;i<counter;i++)
{
printf("\n=== Meeting no %d ===\n",i);
print_meeting(&meetp tr);
}
break;
}
printf("\n=== Empty - so get back to work! ===\n");
}
}while(1);
}