比较两文本程序

功能:比较input1.txt和input2.txt两个文本,有不同的部分则输出0

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=100;
 4 int main()
 5 {
 6     FILE *f1,*f2;
 7     char sa[N],sb[N];
 8     if ((f1=fopen("C:\Users\hemeiwolong\Desktop\input1.txt","r"))==NULL)
 9     {
10         printf("f1 open error
");
11         exit(0);
12     }
13     if ((f2=fopen("C:\Users\hemeiwolong\Desktop\input2.txt","r"))==NULL)
14     {
15         printf("f2 open error
");
16         exit(0);
17     }
18     while (!feof(f1))
19     {
20         fscanf(f1,"%s",sa);
21         fscanf(f2,"%s",sb);
22         printf("%s %s
",sa,sb);
23         if (strcmp(sa,sb)==0)
24         {
25             printf("1
");
26         }
27         else
28         {
29             printf("0
");
30             break;
31         }
32     }
33 
34     return 0;
35 }
原文地址:https://www.cnblogs.com/hemeiwolong/p/10432274.html