I would like to create arrays within an array in C without a pre-defined number of characters or input in the array. The following is my code:
{
int noOfStudents,noOfItems;
int *grades;
int i;
char a[];
printf("Please enter number of students\n");
scanf("%d", &noOfStudents);
printf("Please enter number of items\n");
scanf("%d", &noOfItems);
for (i = 0; i < noOfStudents; i++)
{
a[i] = (int *)malloc((sizeof(int))*noOfItems);
}
I've been thrown an error
c(2133): 'a': unknown size
How do I successfully create arrays within an array by means of malloc?
int **a = malloc(sizeof(int *)*nbOfStudents);first. You want a bidimensional array.