Just to give everyone the satisfaction of how bad this code is:
Code:
#include <stdio.h>
void readticket(FILE* fin, int ticket[]);
int lottery(int ticket[], int winning[]);
int main(void)
{
FILE *fin;
int winning[6],ticket[6];
int i,j;
fin = fopen("lottery.txt", "r");
readticket(fin, winning);
for(i=0; i<6;i++)
{
printf("%d ", winning[i]);
}
while(!feof(fin))
{
scanf("%d \n",readticket); //read ticket
if(lottery==0) //compare ticket, winning using lottery func
printf("Ticket# %d has %d matching numbers \n",&ticket,&winning); //print
}
system("PAUSE");
return 0;
}
void readticket(FILE* fin, int ticket[])
{
int i;
for(i=0;i<6;i++)
fscanf(fin,"%d", &ticket[i]);
}
int lottery(int ticket[], int winning[])
{
{
int i;
int k;
int count=0;
for (i=0;i<6;i++)
for(k=0;k<6;k++)
if (ticket[i]==winning[k])
count++;
return count;
}
}
Code:
LotteryTicket.c: In function `main':
LotteryTicket.c:23: warning: int format, different type arg (arg 2)
LotteryTicket.c:23: error: syntax error before '/' token
LotteryTicket.c:27: warning: implicit declaration of function `system'
LotteryTicket.c:11: warning: unused variable `ticket'
LotteryTicket.c:12: warning: unused variable `j'
As tabstop and my compiler both pointed out, your scanf() is wrong. Always fix syntax errors first so you can test the logic itself instead of wasting time with stupid things like this. This will most likely just waste time crashing your program. If your compiler is not spitting out these types of errors, you need to turn the warning level up higher, preferably to max.
Edit: And actually your entire program logic appears bizarre like you mixed and matched totally different strategies.