Reading in a string from an input file?
Hello,
I am working on my programming assignment.
Basically I need to read in two lines of text for each person, first line is there first and last name and the second line is their lottery ticket numbers. (if there are 5 people then I need to read in 10 lines of text total but analyze two lines at a time).
I am having trouble reading the last an first name using an input file...
Is fgets the only way this can be done? I'd rather just loop and use fscanf but any advice will be appreciated.
Here is my code so far:
Code:
#include <stdio.h>
#include <string.h>
#define MAX_NUM 53
int main () {
FILE *ifp;
ifp = fopen("lottery.txt", "r");
int lottery_num [5], num_tickets, i,z;
char filename;
char full_name[19];
//Scan number of lottery tickets on file
fscanf(ifp, "%d", &num_tickets);
//printf("Please enter the name of the input file with the ticket information.\n"); IGNORE THIS
//scanf("%s", &filename); IGNORE THIS
printf("Please enter the winning lottery numbers.\n");
for(i=0; i<6; i++){
scanf("%d", &lottery_num[i]);
}
for(z=0; z<19; z++){
fscanf(ifp, "%s", &full_name[z]);
}
printf("%s", full_name);
system("PAUSE");
return 0;
}
This is my txt file:
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