首页 > Code > 比较两个文件内容

比较两个文件内容

2008年1月4日 timmy 发表评论 阅读评论 474 views


#include
#include
void main()
{
FILE *f1,*f2;
int l,c;
char ch1,ch2;
if((f1=fopen(“f1.txt”,”r”))==NULL){
printf(“File open error\n”);
exit(0);
}
if((f2=fopen(“f2.txt”,”r”))==NULL){
printf(“File open error\n”);
exit(0);
}
l=c=1;
while(!feof(f1)&&!feof(f2)){
ch1=fgetc(f1);
ch2=fgetc(f2);
if(ch1!=ch2)
break;
else
c++;
if(ch1=='\n'){
c=1;
l++;
}
}
if(fclose(f1)){
printf(“can't close file\n”);
exit(0);
}
if(fclose(f2)){
printf(“can't close file\n”);
exit(0);
}
printf(“l=%d,c=%d\n”,l,c);
}

若日志经rss订阅或导入到外站,可能有些视频和图片无法显示,请点击原文链接查看。
本文链接地址: http://imtimmy.com/%e6%af%94%e8%be%83%e4%b8%a4%e4%b8%aa%e6%96%87%e4%bb%b6%e5%86%85%e5%ae%b9/

转载请注明: 转载自Timmy's Blog

如果你觉得本博内容不错,欢迎 [订阅 Timmy's Blog],以便第一时间了解本博更新内容;


不妨再看看这些相关的日志:

  1. 统计文件中字符
  2. 实验二  抽象数据类型的表示和实现
  3. 实验八 队列的基本操作以及舞伴配对问题
  4. 实验4 栈的应用-算术表达式计算
  5. 输出杨辉三角

分类: Code 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :cool: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O