Hi, I am absolutly lost with this program, I have to compare data in two files and if it matches right to 3rd file. I know it can be done by comparing data while reading from the file, or storing data in an array and then comparing it.
I opened 1st file to compare with , and then I opened 2nd file, but do not understand how to do the actual comparasing.
I am only up to, I'll be appriciated for help, for some explonations...
Code:
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#define F_WANT "/want.names"
int main(int argc, char *argv[])
{
FILE *f1, *f2, *out;
char want_file[10000]; /* declaring a strings to hold contents of the files*/
char topps_file[1000];
char new_file[1000];
char fn[10];
int i;
int year;
/*open want.names file*/
if ((f1=fopen(F_WANT,"r"))==NULL)
{
printf("Error open file %s.\n", F_WANT);
exit(1);
}
else
{
int i=0;
while(fgets(want_file,sizeof want_file ,f1)!=NULL) /*put contents of the want.names into want_file*/
{
fscanf(wants_file,"%*d%s",&input1, &input2);
/* put data into 2 dimentional array */
}
fclose(f1);
/*open topps.xx files using for loop to compare contents with want.name */
for(i=1; i<=12; ++i)
{
year=atoi(argv[i]);
sprintf(fn,"topps.%2d",year);
if((f2=fopen(fn,"r"))==NULL)
{
printf("Error open file %s\n", fn);
exit(2);
}
else
{
int i=0;
while(fgets(topps_file, sizeof topps_file, f2)!=NULL)
{
fscanf(topps_file,"%s",&input);
topps[i] = input;
++i;
}
}
}
fclose(f2);
return 0;
}
}