the program is intended to recieve 'n' number of students and their names and sort them (havent got to the sorting part). I cant figure out why my program crashes when i test it. this is the code:
#include<stdio.h>
#include <stdlib.h>
#define MaxNameLen 100
int main() {
int n;
scanf("%d", &n);
char *names;
char **pointerToNames = (char **) malloc(n * sizeof(char));
if (pointerToNames == NULL)
return 0;
int i;
for (i = 0; i <= n; i++) {
names = (char *) malloc(MaxNameLen);
gets(names);
pointerToNames[i] = names;
}
for (i = 0; i < n; i++) {
free(pointerToNames[i]);
free(names);
}
}