I'm trying to build a program that has a student id array, a course code array of char pointers to string literals, and a registration table 2d array to hold a 1 or 0 whether the student is enrolled in a course or not. So far I am at the point where I am adding the students which works fine. The program also runs as expected when I input a total of 1 course. The issue however is when I try to add more than 1 course code to the courseArray, I'm getting a segmentation error after inputting the codes. I'm unsure how to fix this and no resource on the matter seems to point me in the right direction. Any help with this is appreciated.
#include <stdio.h>
#include "Functions.h"
#include <stdbool.h>
int main()
{
//declaring variables for number of students and courses
int numStudents, numCourses;
//declaring 2d array for the registration table
int registrationTable[numStudents][numCourses];
//prompting user input for number of students and storing in numStudents
printf("How many students would you like to register: \n");
scanf("%d", &numStudents);
//create student array based on numStudents
int studentArray[numStudents];
//Prompting user input for id's of students in student array
for (int i = 0; i < numStudents; i++)
{
printf("Please enter the student ID for student %d: \n", i + 1);
scanf("%d", &studentArray[i]);
}
//Prompting user input for number of courses offered and storing in numCourses
printf("How many courses are you offering: \n");
scanf("%d", &numCourses);
//create couses array based on numCouses
char *courseArray[numCourses];
//Prompting user input for course codes in course array
for (int i = 0; i < numCourses; i++)
{
printf("Please enter the course code for course %d: \n", i + 1);
scanf(" %s", courseArray[i]);
}
validate(studentArray, courseArray, numStudents, numCourses);
return 0;
}