I am try to change my previous created program that get student data from 5 students and stores it into a data base. i want to make it that you can choose the amount of students to put in. I was thinking of asking for the number then changing the fix value maxElements to that number but i dont know how
#include "strlib.h"
#include "simpio.h"
#include "genlib.h"
#include "string.h"
#include <cstdlib>
#define size 100
#define maxElements 5
typedef char sting [size];
typedef struct stud // *studPtr
{
string name;
string address;
string birthDate;
} *studPtr;
typedef struct studDB // *studDBPtr
{
studPtr clas[maxElements];
int numstuds;
} *studDBPtr;
studDBPtr initDB ();
studPtr initOneRec ();
void displayBirthDates(studDBPtr pd);
void displayPrompt();
int main()
{
studDBPtr pdb;
displayPrompt();
pdb=initDB();
displayBirthDates(pdb);
system("pause");
}
void displayPrompt()
{
printf("The program creates a simple data base containing students' data.\n");
printf("The program initializes each record and displays \n");
printf("The students' names and their birthdates.\n\n");
}
studDBPtr initDB(void)
{
studDBPtr pd;
studPtr pt;
int i, maxstudents;
printf("How many students are there: ");
maxstudents=GetInteger();
maxElements=maxstudents;
pd=(studDBPtr) malloc(sizeof(*pd));
printf("Enter student data\n");
for(i=0; i<maxstudents; i++)
{
pt=initOneRec();
pd->clas[i]=pt;
}
pd->numstuds=i+1;
return(pd);
}
studPtr initOneRec(void)
{
studPtr pt;
pt=(studPtr) malloc(sizeof(*pt));
printf("Enter name: ");
pt->name=GetLine();
printf("Enter address: ");
pt->address=GetLine();
printf("Enter birth date: ");
pt->birthDate=GetLine();
printf("\n");
return(pt);
}
void displayBirthDates (studDBPtr pd)
{
int i;
printf("The students' Birth Dates are: \n\n");
for(i=0; i<maxElements; i++)
{
printf("%s \t %s\n", pd->clas[i]->name, pd->clas[i]->birthDate);
}
}