ok i tried to write it
but how to know which string is the smallest and which file it belongs to
without writing the previous function that i showed
??
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
char* equal(char*f1,char*f2,char*f3);
char* smallest(char*f1,char*f2,char*f3);
int main()
{
FILE *file1,*file2,*file3;
char f1[20];
char f2[20];
char f3[20];
char* small;
char* equall;
file1=fopen("c:\\1.txt","r");
file2=fopen("c:\\2.txt","r");
file3=fopen("c:\\3.txt","r");
while(fgetc(f1)!=EOF)||(fgetc(f2)!=EOF)||(fgetc(f1)!=EOF))
{
fscanf(file1,"%9s",f1);
fscanf(file2,"%9s",f2);
fscanf(file3,"%9s",f3);
small=smallest(f1,f2,f3);
equall=equal(f1,f2,f3);
}
fclose(file1);
fclose(file2);
fclose(file3);
return 0;
}
char* smallest(char*f1,char*f2,char*f3,FILE* file1,FILE* file2,FILE* file3)
{
char* pLowest = f1;
if(strcmp(pLowest, f2) > 0)
pLowest = f2;
if(strcmp(pLowest, f3) > 0)
pLowest = f3;
return pLowest;
}
char* equal(char*f1,char*f2,char*f3)
{
if(strcmp(f1,f3)==0)
{
return f1;
}
if(strcmp(f2,f3)==0)
{
return f2;
}
return NULL;
}