How to get a 2d character array from a file?
Code:
char men_names[num_each][MAX_NAMELEN];
char women_names[num_each][MAX_NAMELEN];
for (j=0; j < num_each; j++)
{
fscanf(ifp, "%s", &men_names[j]);
printf("%s\n", men_names[j]);
}
for (j=0; j < num_each; j++)
{
fscanf(ifp, "%s", &women_names[j]);
printf(ifp, "%s\n", women_names[j]);
}
Where num_each is an integer which ive already scanned for that represents how many women or (not combined) men there are. And MAX_NAMELEN is defined as 19.
The names in the file are separated by spaces and the names of the men are on one line and the names of the women are on the next.
I know fgets would be good for this but I never can get it to work if I use it with fscanf and since I am scanning in many integers, I really don't want to convert them all from strings to integers if possible.
(Note this is CS 1 so just take that into consideration when you are helping)