Code:
#include <stdio.h>
#include <string.h>
#define MAX_NUM 53
//declare struct of type lotto
struct lotto
{
char firstname [19];
char lastname [19];
int ticket_num[5];
int winnings;
};
int main ()
{
struct lotto *info;
int winning_nums [5], num_tickets, moneywon;
int i, q, g, f, r, t, win3, win4, win5, win6;
int matches=0;
char filename[20];
FILE *ifp;
//Prompt user for filename with lottery ticket info
printf("Please enter the filename with the ticket information.\n");
scanf("%s", &filename);
ifp = fopen(filename, "r");
//Scan number of lottery tickets on file
fscanf(ifp, "%d", &num_tickets);
//Allocate dynamic memory
info=malloc(num_tickets*sizeof(struct lotto));
//Scan first and last name for lottery info file
for(t=0; t<num_tickets; t++){
fscanf(ifp, "%s %s", &info[t].lastname, &info[t].firstname);
}
printf("%s\n", info[0].firstname, info[0].lastname); // HERE IS WHERE I AM HAVING TROUBLE.
IT SCANS FIRST AND LAST NAME FROM THE .TXT doc GOOD WHEN I TEST IT WITH
"info[0].firstname" but NOT with "info[1].firstname... info[2], etc...
Text Document:
5
Llewellyn Mark
1 15 19 26 33 46
Young Brian
17 19 33 34 46 47
Cazalas Jonathan
1 4 9 16 25 36
Siu Max
17 19 34 46 47 48
Balci Murat
5 10 17 19 34 47
NOTE: I am simply trying to scan all the last names and first names at once and then have access to each last or first name. After attempting to come up with the code, I was trying to test it by printing out different last names that were stored in the array. Please HELP.