diff options
-rw-r--r-- | 7.6/main.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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); } + |