I know I've made an error somewhere that is causing my resizable array to only have one element and nothing else, but I can't find it and my compiler's debug function doesn't work (school computer, go figure).
Here's the resizing function and the function that calls it, ignore the C++ input and output calls, that's the only thing C++ in this program.
Code:
int main(void)
{
int sel = 0, count = 1;
long key = 0;
struct Employee *emp;
//old compiler, it makes me cast malloc
emp = (struct Employee *)malloc(sizeof *emp);
if(emp == NULL)
return EXIT_FAILURE;
else{
sel = menu();
while(sel != 6){
if(sel == 1)
makeNew(emp, &count);
else if(sel == 6)
break;
else
cout<<"ERROR: Invalid input"<<flush;
sel = menu();
}
}
free(emp);
return EXIT_SUCCESS;
}
int makeNew(struct Employee *empArray, int *size)
{
int count = *size;
struct Employee *temp;
//ditto, my old compiler makes me cast realloc as well
temp = (struct Employee *)realloc(empArray, ++count * sizeof *empArray);
if(temp == NULL)
return EXIT_FAILURE;
*size++;
empArray = temp;
//Information for the new element is entered here
free(temp);
return EXIT_SUCCESS;
}
The first time I call the makeNew function, I actually do reallocate it but the size stays the same when I loop through the array and try to print everything. The second time I call the makeNew function it returns fail.