Hi Guys,
I have the following code that is working fine and I was wondering what is the preffered way to send an array of struct to a function, and if I should make any changes to make this code look more proffestional.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
typedef struct
{
int day,month,year;
} Date;
typedef struct
{
Date date;
int hh,mm;
char description[100];
} Meetings;
void ShowMenu()
{
system("CLS");
puts("a. Add");
puts("d. Delete");
puts("u. Update");
puts("s. Show All");
puts("x. Exit");
}
void AddMeeting(Meetings *m)
{
puts("Date:");
scanf("%d/%d/%d",&m->date.day, &m->date.month, &m->date.year);
puts("Hour:");
scanf("%d:%d",&m->hh, &m->mm);
flushall();
puts("Description:");
gets(m->description);
}
Meetings *AllocateMemory(Meetings *m, int *iTotal)
{
++(*iTotal);
m=realloc(m,(*iTotal)*sizeof(*m));
if (m==NULL)
{
puts("Not enough memory!");
exit(1);
}
return m;
}
int main(void)
{
Meetings *meetings=NULL;
int iTotal=0;
char ch;
do
{
ShowMenu();
ch=getch();
switch(ch)
{
case 'a':
meetings=AllocateMemory(meetings,&iTotal);
AddMeeting(&meetings[iTotal-1]);
break;
}
} while (ch!='x');
if (meetings!=NULL)
free(meetings);
return 0;
}
Many Thanks!!!