【c语言】判断两个文件是否一致 发表于 2017-06-19 | 分类于 c 学习笔记判断两个文件是否一致 并打印出第一个不同行1234567891011121314151617181920212223242526272829303132333435363738394041424344#include <stdio.h>;#include <string.h>;#define MAXLINE 100void diff(char *a, char *b);int main(int argc, char *argv[]){ if(3 != argc){ printf("参数不正确\n"); return -1; } diff(argv[1], argv[2]); return 0;}void diff(char *a, char *b){ FILE *afp; FILE *bfp; char aline[MAXLINE]; char bline[MAXLINE]; if((afp = fopen(a, "r")) == NULL){ printf("Error: not file %s", a); return; } if((bfp = fopen(b, "r")) == NULL){ printf("Error: not file %s", b); return; } while((fgets(aline, MAXLINE, afp) == aline) && (fgets(bline, MAXLINE, bfp) == bline)){ if(strcmp(aline, bline) != 0){ printf("%s:%s", a, aline); printf("%s:%s", b, bline); break; } } fclose(afp); fclose(bfp);}