From e2785e3c53695045eef4a6d435b488e6045a087a Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 14 May 2023 11:24:06 +0530 Subject: 7.6: more verbose filecmp, prefere the first one --- 7.6/main.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to '7.6') diff --git a/7.6/main.c b/7.6/main.c index c86174e..aab5e5e 100644 --- a/7.6/main.c +++ b/7.6/main.c @@ -25,12 +25,23 @@ int main(int argc, char *argv[]) void flcmp(FILE *fp1, FILE *fp2) { char l1[MAXLEN], l2[MAXLEN]; + char *lp1, *lp2; - while (fgets(l1, MAXLEN, fp1) && fgets(l2, MAXLEN, fp2)) { - if (strcmp(l1, l2)) { - printf(">>> %s", l1); - printf("<<< %s", l2); - break; + do { + lp1 = fgets(l1, MAXLEN, fp1); + lp2 = fgets(l2, MAXLEN, fp2); + + if (lp1 == l1 && lp2 == l2) { + if (strcmp(l1, l2)) { + printf("first difference in line\n%s\n", lp1); + lp1 = lp2 = NULL; + } + } else if (lp1 == NULL && lp2 == l2) { + printf("end of first file at line\n%s\n", lp2); + } else if (lp1 == l1 && lp2 == NULL) { + printf("end of first file at line\n%s\n", lp1); } - } + + } while (lp1 == l1 && lp2 == l2); } + -- cgit v1.2.3