Hello all, I am creating a program that uses a dynamic array to store students. My code compiles but i keep getting a runtime error which prints out a bunch of stuff, but the main thing being:

*** glibc detected *** ./a.out: realloc(): invalid pointer: 0xb7fc2e00 ***

so apparently there is a problem with my realloc but I just can't seem to figure out what it is. As far as I can see it should work. Any help with this would be greatly appreciated.

Here is my main which is pointless right now. Basically it's just set up to test whether the add function works.

Code:
#include <stdio.h>
#include <stdlib.h>
#include "student.h"

int main()
{
	
	student *array;
	student std1;
	int number_of_elements = 0;
	int array_size = 0;
	
	std1.lastname = "smith";
	std1.firstname = "bob";
	std1.score = 50;

	add(array, std1, &number_of_elements, &array_size);
	
	free(array);
	return 0;
}
And my header file

Code:
#include <stdlib.h>

#ifndef STUDENT_C
#define STUDENT_C
typedef struct student
{
	char *lastname;
	char *firstname;
	int score;
} student;

void add(student*, student, int*, int*);

#endif
and finally the important one. The student file which contains the dynamic memory function. Again the error seems to be on the realloc line.

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)++;
}