aboutsummaryrefslogtreecommitdiff
path: root/7.6
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-14 11:24:06 +0530
committersinanmohd <sinan@firemail.cc>2023-05-14 11:24:06 +0530
commite2785e3c53695045eef4a6d435b488e6045a087a (patch)
tree7c5b0193131251c605aa013dbd64c864fba26b91 /7.6
parentb7c333d192cfa93dcfd41275309b4cf0b60a066b (diff)
7.6: more verbose filecmp, prefere the first one
Diffstat (limited to '7.6')
-rw-r--r--7.6/main.c23
1 files changed, 17 insertions, 6 deletions
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);
}
+