#include<stdio.h>
#include<conio.h>
#include<string.h>
char tu[20],tg[20];
int i=0,k=0;
void doctu(FILE * f){
char c,d;
int i=0;
do{
c=fgetc(f);
if(feof(f)) break;
if(c>64&&c<91||c>96&&c<123) tg[i++]=c;
}
while (i==0||c>64&&c<91||c>96&&c<123);
tg[i]=0;
}
int main()3
{
FILE *f1,*f2,*f3,*f4,*f5,*f6,*f7,*f8,*f9,*f10;
char s[30],a[10],b[10],c[10],vb1,vb2;
int sl=0,j,cach=0,e=0,f=0,sh=0;
printf("\n nhap vao so tu tieng anh < 4:");
fflush(stdin);
gets(s);
for (i=0;i<strlen(s);i++)
if (s[i]==32) cach++;
if (cach==2)
{
while(s[e]!=32)a[f++]=s[e++];f=a[f]=0;e++;
while(s[e]!=32)b[f++]=s[e++];f=b[f]=0;e++;
while(s[e]!=0)c[f++]=s[e++];c[f]=0;
if((f1=fopen("9.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f1)) break;
}
while(i);
fclose(f1);
if((f2=fopen("10.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f2);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sh++;
if (strcmp(strlwr(c),strlwr(tu))==0) sh++;
if (strcmp(strlwr(b),strlwr(tu))==0) sh++;
i++;
if (feof(f2)) break;
}
while(i);
fclose(f2);
}
if((f3=fopen("1.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f3)) break;
}
while(i);
fclose(f3);
if((f4=fopen("2.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f4)) break;
}
while(i);
fclose(f4);
if((f5=fopen("3.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f5)) break;
}
while(i);
fclose(f5);
if((f6=fopen("4.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f6)) break;
}
while(i);
fclose(f6);
if((f7=fopen("5.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f7)) break;
}
while(i);
fclose(f7);
if((f8=fopen("6.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f8)) break;
}
while(i);
fclose(f8);
if((f9=fopen("7.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f9)) break;
}
while(i);
fclose(f9);
if((f10=fopen("8.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(c),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f10)) break;
}
while(i);
fclose(f10);
if (cach==1)
{while(s[e]!=32)a[f++]=s[e++];f=a[f]=0;e++;
while(s[e]!=0)b[f++]=s[e++];b[f]=0;
if((f1=fopen("9.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f1)) break;
}
while(i);
fclose(f1);
if((f2=fopen("10.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f2);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sh++;
if (strcmp(strlwr(b),strlwr(tu))==0) sh++;
i++;
if (feof(f2)) break;
}
while(i);
fclose(f2);
}
if((f3=fopen("1.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f3);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f3)) break;
}
while(i);
fclose(f3);
if((f4=fopen("2.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f4);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f4)) break;
}
while(i);
fclose(f4);
if((f5=fopen("3.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f5);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f5)) break;
}
while(i);
fclose(f5);
if((f6=fopen("4.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f6);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f6)) break;
}
while(i);
fclose(f6);
if((f7=fopen("5.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f7);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f7)) break;
}
while(i);
fclose(f7);
if((f8=fopen("6.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f8);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f8)) break;
}
while(i);
fclose(f8);
if((f9=fopen("7.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f9);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f9)) break;
}
while(i);
fclose(f9);
if((f10=fopen("8.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f10);strcpy(tu,tg);
if (strcmp(strlwr(a),strlwr(tu))==0) sl++;
if (strcmp(strlwr(b),strlwr(tu))==0) sl++;
i++;
if (feof(f10)) break;
}
while(i);
fclose(f10);
if (cach==0)
{
if((f1=fopen("9.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f1);strcpy(tu,tg);
if (strcmp(strlwr(s),strlwr(tu))==0) sl++;
i++;
if (feof(f1)) break;
}
while(i);
fclose(f1);
if((f2=fopen("10.txt","rt"))==NULL) printf ("\nKhong mo dc tep");
do
{
doctu(f2);strcpy(tu,tg);
if (strcmp(strlwr(s),strlwr(tu))==0) sh++;
i++;
if (feof(f2)) break;
}
while(i);
fclose(f2);
}
if((f3=fopen("output.txt","wt"))==NULL) printf ("\nKhong mo dc tep");
if (sl>=sh)
{
fprintf(f3,"|%d| %s co %d tu giong cac tu trong cum tu : %s vua nhap\n",k+1,vb1,sl,s);
fprintf(f3,"|%d| %s co %d tu giong cac tu trong cum tu : %s vua nhap\n",k+2,vb2,sh,s);
}
else
{
fprintf(f3,"|%d| %s co %d tu giong cac tu trong cum tu : %s vua nhap\n",k+1,vb2,sh,s);
fprintf(f3,"|%d| %s co %d tu giong cac tu trong cum tu : %s vua nhap\n",k+2,vb1,sl,s);
}
fclose(f3);
getch();
} |