Code:
#include <stdlib.h>
#include <stdio.h>
//Record Struct
typedef struct{
char first[20];
char last[20];
int numbers[6];
}RECORD;
//function prototypes
void writeRecord ( RECORD* , FILE*, int);
void Winners (RECORD*,int,int);
//Enumarated winnings
enum Scenario{
three = 10,
four = 100,
five = 10000,
six = 1000000
};
main(){
FILE* fp;
int num_people,i,WinNums[6] = {0};
char file_name[20];
RECORD* people;
//asks and opens the file the user puts in
printf("Enter the name of the file with the ticket data.\n");
scanf("%s",file_name);
fp = fopen(file_name,"r");
if(fp == NULL){
printf("Can't find the file you have entered");
system("pause");
exit(-1);
}
// Reads the amount of people in lottery and allocates memory
fscanf(fp,"%i",&num_people);
people = (RECORD*) malloc(num_people*sizeof (RECORD));
// Start to put information about people in the Record array people
writeRecord(people, fp, num_people);
//Asks user for the winning numbers and error check
printf("Enter the winning Lottery numbers\n");
scanf("%i %i %i %i %i %i",&WinNums[0],&WinNums[1],&WinNums[2],&WinNums[3],&WinNums[4],&WinNums[5]);
while(WinNums[0] > WinNums[1] || WinNums[1] > WinNums[2]|| WinNums[2] > WinNums[3] || WinNums[3] > WinNums[4]||WinNums[4] > WinNums[5]){
printf("you entered numbers in non ascending order, try again.\n");
printf("Enter the winning Lottery numbers\n");
scanf("%i %i %i %i %i %i",&WinNums[0],&WinNums[1],&WinNums[2],&WinNums[3],&WinNums[4],&WinNums[5]);
}
//Checks amount of numbers matched and outputs winners
Winners(people,num_people,WinNums);
//closes file and free's up the memory allocated
fclose(fp);
free(people);
system("pause");
}
void writeRecord (RECORD* people,FILE* fp,int num_people){
int i;
//scanning the file and encoding the data into the struct
for(i=0; i<num_people;i++){
fscanf(fp,"%s %s",people[i].last,people[i].first);
fscanf(fp,"%i",people[i].numbers);
fscanf(fp,"%i",people[i].numbers+1);
fscanf(fp,"%i",people[i].numbers+2);
fscanf(fp,"%i",people[i].numbers+3);
fscanf(fp,"%i",people[i].numbers+4);
fscanf(fp,"%i",people[i].numbers+5);
}
}
void Winners(RECORD* people,int num_people,int WinNums[]){
int i,j,k,num_matched;
for(i=0; i < num_people; i++){
num_matched = 0;
for(j=0; j<6; j++){
for(k=0; k<6;k++){
if(people[i].numbers[j] == WinNums[k]){
num_matched++;
}
}
if(num_matched == three){
}
}
}
as you can see i'm trying to get all the matches for one profile. I know there is an easier code for it but i forgot.