ahhh ok I see what you mean, just so we can change the original it needs to be passed in as an address. I did that and now it seems to work perfectly for the first time I use add but if I use it again it segfaults. This is my new Student.
Code:
#include <stdlib.h>
#include <stdio.h>
#include "student.h"
void add(student **array, student item, int *number_of_elements, int *array_size)
{
if (*number_of_elements == *array_size) /*resize array*/
{
if (*array_size == 0)
{
*array_size = 1;
}
else
{
*array_size = *array_size * 2;
}
*array = (student*)realloc(*array, ((*array_size) * sizeof(student)));
if (*array == 0)
{
printf("no space for memory");
exit(1);
}
}
*array[*number_of_elements] = item;
(*number_of_elements)++;
}