ok i did that
but i dont get
003
005
file .
intead i get
005
999999
999999
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
int equal(char*f1,char*f2,char*f3);
int smallest(char*f1,char*f2,char*f3);
int main()
{
FILE *file[3];
FILE *common;
char f[3][20];
int small;
int equall;
file[0]=fopen("g:\\1.txt","r");
file[1]=fopen("g:\\2.txt","r");
file[2]=fopen("g:\\3.txt","r");
common=fopen("g:\\common.txt","w");
fscanf(file[0],"%9s",f[0]);
fscanf(file[1],"%9s",f[1]);
fscanf(file[2],"%9s",f[2]);
while(fgetc(file[0])!=EOF||fgetc(file[1])!=EOF||fgetc(file[2])!=EOF)
{
small=smallest(f[0],f[1],f[2]);
equall=equal(f[0],f[1],f[2]);
if(equall!=-1)
{
fputs(f[equall],common);
fscanf(file[equall],"%20s",f[equall]);
fputc('\n',common);
}
if(getc(file[small])!=EOF)
{
fscanf(file[small],"%20s",f[small]);
}
else
{
strcpy(f[small],"999999");
}
}
fclose(file[1]);
fclose(file[2]);
fclose(file[0]);
fclose(common);
return 0;
}
int smallest(char* f_a,char* f_b,char* f_c)
{
int i=0;
char* pLowest = f_a;
if(strcmp(pLowest, f_b) > 0)
{
i=1;
pLowest = f_b;
}
if(strcmp(pLowest, f_c) > 0)
{
pLowest = f_c;
i=2;
}
return i;
}
int equal(char* f1,char*f2,char*f3)
{
if(strcmp(f1,f3)==0)
{
return 0;
}
if(strcmp(f1,f2)==0)
{
return 1;
}
if(strcmp(f2,f3)==0)
{
return 2;
}
return -1;
}