用C语言编一个文件对比的程序

来源:百度知道 编辑:UC知道 时间:2024/05/18 12:52:51
两个文本文件
里边的数据格式是:每一行一条11位字符,每个文件里有5万条数据
要求:从第一个文本里读取一行数据,跟第二个文本里的所有数据做对比
把相同的结果输入出来

#include<stdio.h>
#include<string.h>
#define SIZE 12
#define LINE 50000
int main()
{
FILE *from0,*from1;
char str0[SIZE],str1[SIZE];
char file1[256],file2[256];
int i,j;
printf("Input the name of file1:\n");
gets(file1);
printf("Input the name of file2:\n");
gets(file2);
if((from0=fopen(file1,"r"))==NULL)
{
printf("Can't open file1 :%s\n",file1);
getch();
return 0;
}
if((from1=fopen(file2,"r"))==NULL)
{
printf("Can't open file2 :%s\n",file2);
fclose(from0);
getch();
return 0;
}
for(i=LINE;i!=0;i--)
{
fscanf(from0,"%s",str0);
fseek(from1,0,SEEK_SET);
for(j=LINE;j!=0;j--)
{
fscanf(from1,"%s",str1);
if(!strcmp(str0,str1))
{
printf("%s\n