i got an array
char f[3][20];
so when i am doing
Code:
fputs(f[equal],common);
why i am getting
error C2107: illegal index, indirection not allowed
my code is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define false 0
#define true 1
char* 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;
char* equall;
file[1]=fopen("c:\\1.txt","r");
file[2]=fopen("c:\\2.txt","r");
file[3]=fopen("c:\\3.txt","r");
common=fopen("c:\\common.txt","w");
fscanf(file[1],"%9s",f[1]);
fscanf(file[2],"%9s",f[2]);
fscanf(file[3],"%9s",f[3]);
while(fgetc(file[1])!=NULL||fgetc(file[2])!=NULL||fgetc(file[3])!=NULL)
{
small=smallest(f[1],f[2],f[3]);
equall=equal(f[1],f[2],f[3]);
fputs(f[equal],common);
fputc('\n',common);
fscanf(file[small],"%20s",f[small]);
}
fclose(file[1]);
fclose(file[2]);
fclose(file[3]);
return 0;
}
int smallest(char*f[1],char*f[2],char*f[3])
{
int i=1;
char* pLowest = f[1];
if(strcmp(pLowest, f[2]) > 0)
i=2;
pLowest = f[2];
if(strcmp(pLowest, f3) > 0)
pLowest = f[3];
i=3;
return i;
}
int equal(char*f1,char*f2,char*f3)
{
if(strcmp(f1,f3)==0)
{
return 1;
}
if(strcmp(f2,f3)==0)
{
return 2;
}
return NULL;
}