Skip to content

Commit a53f1f9

Browse files
committed
minor tweaks
1 parent 7cd6ae5 commit a53f1f9

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

chapter07/7-8.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@
77
#include <stdio.h>
88
#include <stdlib.h>
99

10-
#define LINE 81
11-
#define PAGEBREAK 3840 /* characters per page */
10+
#define LINE 81 /* characters per line */
11+
#define PAGEBREAK 3840 /* characters per page ~ 500 word/page */
1212

1313
/* functions */
14-
int pagecount(FILE *);
14+
int pagecount(FILE *);
1515
void printcover(char *, int);
1616

1717
int pagecount(FILE *f)
1818
{
19-
int c;
2019
int count = 0;
2120

22-
while ((c = getc(f)) != EOF)
21+
while (getc(f) != EOF)
2322
count++;
24-
2523
return (count < PAGEBREAK) ? 1 : count / PAGEBREAK;
2624
}
2725

@@ -34,26 +32,26 @@ void printcover(char *s, int n)
3432
printf("Page count: %i\n", n);
3533
printf("************************\n");
3634

37-
for (i = 4; i <= (PAGEBREAK / LINE); ++i)
35+
for (i = 4; i <= (PAGEBREAK / LINE); ++i) /* i = 4 to skip above lines */
3836
printf("\n");
3937
}
4038

4139
int main(int argc, char *argv[])
4240
{
4341
FILE *fp;
4442
char *prog = argv[0];
45-
int pages;
43+
int pages, c;
4644

4745
while (--argc > 0)
4846
if ((fp = fopen(*++argv, "r")) == NULL) {
4947
fprintf(stderr, "%s: can't open %s\n", prog, *argv);
5048
exit(EXIT_FAILURE);
5149
} else {
5250
pages = pagecount(fp);
53-
rewind(fp); /* rewind the input stream */
51+
rewind(fp); /* rewind input stream */
5452
printcover(*argv, pages);
55-
while (!feof(fp)) /* print file */
56-
putc(getc(fp), stdout);
53+
while ((c = getc(fp)) != EOF) /* print file */
54+
fprintf(stdout, "%c", c);
5755
fclose(fp);
5856
}
5957
exit(EXIT_SUCCESS);

0 commit comments

Comments
 (0)