首页 > 其他 > 详细

比较两文本程序

时间:2019-02-25 17:58:35      阅读:139      评论:0      收藏:0      [点我收藏+]

功能:比较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\n");
11         exit(0);
12     }
13     if ((f2=fopen("C:\\Users\\hemeiwolong\\Desktop\\input2.txt","r"))==NULL)
14     {
15         printf("f2 open error\n");
16         exit(0);
17     }
18     while (!feof(f1))
19     {
20         fscanf(f1,"%s",sa);
21         fscanf(f2,"%s",sb);
22         printf("%s %s\n",sa,sb);
23         if (strcmp(sa,sb)==0)
24         {
25             printf("1\n");
26         }
27         else
28         {
29             printf("0\n");
30             break;
31         }
32     }
33 
34     return 0;
35 }

 

比较两文本程序

原文:https://www.cnblogs.com/hemeiwolong/p/10432274.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!