Originally Posted by
hk_mp5kpdw
Not addressing the OPs problem, but this is problematic:
Code:
int lottery_num [5], num_tickets, i,z;
...
printf("Please enter the winning lottery numbers.\n");
for(i=0; i<6; i++){
scanf("%d", &lottery_num[i]);
}
The array has 5 valid indexes from 0-4 but the loop goes from 0-5.
Also:
I believe this is problematic:
Code:
for(z=0; z<19; z++){
fscanf(ifp, "%s", &full_name[z]);
0-18 is 19 indexes, you said you had to read 20.
As for your issue, if you need to save each name, a 2D array would suit you well.
Code:
char all_names[5][20];
int lottery_numbers[5][5]
for (int i = 0 ; i < 5 ; ++i)
{
scanf("%s", all_names[i];
for (int j = 0 ; j < 5 ; ++j)
{
scanf("%d", lottery_numbers[i][j];
}
}
I don't typically use scanf, but you get the idea.
So if you have a 5x20 char array (5 people, 20 char per name), and then a "parallel" 2D array, that's 5x5 (5 people, 5 lottery numbers), you can load them at once.
concept is:
Code:
(looping over people)
(add their name to the names array)
(looping over their numbers)
(add their numbers to the numbers array)
(end looping over their numbers)
(end looping over the people)
Now what you have names:
ie.
Code:
printf("%s", all_names[0]); // prints 1st person's name
printf("%s", all_names[1]); // prints 2nd person's name
And their numbers:
ie.
Code:
printf("%i", lottery_numbers[0][0]); // prints 1st person's 1st number
printf("%i", lottery_numbers[0][1]); // prints 1st person's 2nd number
printf("%i", lottery_numbers[0][2]); // prints 1st person's 3rd number
printf("%i", lottery_numbers[4][3]); // prints 5th person's 4th number
I hope that makes some sense to you .