I am trying to print the records after adding on to the original amount of records, and I am successful in doing so within the addRecords function, but outside of the function I have an error, but I am having understanding how. I'm passing the Names array through pointer and the classSize variable is global. So I don't see why it works in the addRecords function and not in the main funtion. All help is appreciated, thanks in advance.
#include <stdio.h>
#include <stdlib.h>
#define STRINGSIZE 21
int classSize;
void addRecords( char **Names);
int main() {
char **Names;
int i;
//User will be able to choose how many records he woudld like to input.
printf("Please indicate number of records you want to enter:\n");
scanf("%d", &classSize);
Names = malloc(classSize*sizeof(char*));
for (i = 0; i < classSize; i++) {
Names[i] = malloc(STRINGSIZE * sizeof(char));
}
printf("Please input records of students (enter a new line after each record), with following format: first name....\n");
for (i = 0; i < classSize; i++) {
scanf("%s", *(Names + i));
}
for (i = 0; i < classSize; i++) {
printf("%s ", *(Names+i));
printf("\n\n");
}
addRecords(Names);
printf("SECOND PRINT\n\n");
for (i = 0; i < classSize; i++) {
printf("%s \n", *(Names+i));
}
}
void addRecords(char **Names) {
int addition, i, temp;
temp = classSize;
printf("How many records would you like to add?\n");
scanf("%d", &addition);
classSize += addition;
Names = realloc(Names, (classSize) * sizeof(char*));
for (i = temp; i < (classSize); i++) {
Names[i] = malloc(STRINGSIZE * sizeof(char));
}
printf("Please input records of students (enter a new line after each record), with followingformat: first name....\n");
for (i=temp; i<classSize; i++) {
scanf("%s", *(Names +i));
}
printf("\n\n");
printf("FIRST PRINT\n\n");
for (i = 0; i < classSize; i++) {
printf("%s \n", *(Names+i));
}
printf("\n\n");
}