Skip to content

Commit 73d95fe

Browse files
committed
Close files immediately after reading
1 parent 2e79bd6 commit 73d95fe

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

chapter07/7-6.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,18 @@ int main(int argc, char *argv[])
5151
f1ln++; /* count successfully read lines */
5252
if (getLine(file[2], f2line, MAXLEN) > 0)
5353
f2ln++; /* count successfully read lines */
54-
5554
if ((result = strcmp(f1line, f2line)) != 0)
5655
break; /* found mismatching line */
5756
}
5857

58+
fclose(file[1]);
59+
fclose(file[2]);
60+
5961
if (result != 0) {
6062
fprintf(stdout, "%s: %i: %s", f1name, f1ln, f1line);
6163
fprintf(stdout, "%s: %i: %s", f2name, f2ln, f2line);
6264
} else
6365
printf("%s and %s are identical\n", f1name, f2name);
6466

65-
fclose(file[1]);
66-
fclose(file[2]);
67-
6867
exit(EXIT_SUCCESS);
6968
}

0 commit comments

Comments
 (0)