I'm working on a database program and I'm using array's to store the names entered into the program but seeing that Strings are already char arrays, it's become quite difficult. I'm having problems using 2 dimensional arrays to do this. Can anyone help? Here's the commented code, it's not too long. Thanks!
Code:
int main() //includes and such are above; no other functions yet. :)
{
int i = 0, namesEntered = 1, *nePtr; //integers to be used...
char name[ARRAY_MAX], nameInSlot[ARRAY_MAX][i]; //array's of chars.. "strings"
nePtr = &namesEntered; //namesEntered ("ne") pointer points to the address of the variable...
printf("How many names to enter: ");
scanf("%d", nePtr); //get the amount they entered.
fflush(stdin);
printf("\n\n[%d character limit]\n", (ARRAY_MAX - 1));
for (i = 0; i <= (namesEntered - 1); i++)
{
printf("Enter name %d: ", (i + 1));
gets(name);
nameInSlot[ARRAY_MAX][i] = name[ARRAY_MAX]; //this SHOULD put the value of the string
//entered into a 2d array which consists of an string and
//and index to shove it into.... note the "SHOULD"
}
printf("\nNames:\n");
for (i = 0; i <= namesEntered; i++) //loop for output.
printf("%s\n", nameInSlot[ARRAY_MAX][i]); //ends up all it does is print "(null)" odd.
//or crashes the whole program. blah.
system("pause"); //press anykey...
return 0; //exit
}