just having a few issues here in printing multiple lines to a txt file.
basically my lotto program searches and matches the same numbers between two arrays however when there is more than one match its only prints 1 line, not all of them.
any help or suggestions would be much appreciated
insert
Code:
int main(void)
{
FILE *fpointer;
fpointer = fopen("bacon.txt", "w");
int a;
int i;
int j;
int x;
int y;
int selection[6];
int lotto[6];
int match[6];
char answer;
x=0;
y=0;
i=0;
a=0;
printf("Hello and Welcome to Donaldson's Super Duper Lottery! \n \n");
printf("Please enter your 6 lucky numbers between 1 and 22: \n \n");
printf("Enter selected NUMBER then hit return to enter next number below \n \n");
printf(" \n");
for(i=0 ; i<6; i++)
{
scanf("%d", &selection[i]);
}
printf("\n Your Lucky Numbers for tonights game: \n");
for (i=0; i<6; i++){
printf("%5d", selection[i]);
}
printf("\n\n\n Ready to Draw???? PRESS 1 then RETURN TO REVEAL! \n");
scanf("%d", &answer);
if (answer == 1){
printf(" \n\n Tonights Lucky Draw Numbers are: \n");
srand(time(NULL));
for(j=0 ; j<6 ;j++){
lotto[j] = rand()%6+1;
printf("%5d", lotto[j]);
}}
printf("\n \n \n Ready to see if your matching numbers??? PRESS 1 then RETURN TO REVEAL! \n");
scanf("%d", &answer);
if (answer == 1){
for (x=0;x<6;x++){
for(y=0;y<6;y++){
if(selection[x]== lotto[y])
{match[a] = selection[x];
printf("\n Number %d is a WINNER!", match[a]);
fprintf(fpointer,"Number %d is a WINNER! \n", match[a]);
fclose(fpointer);
}}}
if(match [a]==0)
printf("\n You have no winning numbers...YOU LOSE! \n \n \n");
return(0);