7
7
#include <stdio.h>
8
8
#include <stdlib.h>
9
9
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 */
12
12
13
13
/* functions */
14
- int pagecount (FILE * );
14
+ int pagecount (FILE * );
15
15
void printcover (char * , int );
16
16
17
17
int pagecount (FILE * f )
18
18
{
19
- int c ;
20
19
int count = 0 ;
21
20
22
- while (( c = getc (f ) ) != EOF )
21
+ while (getc (f ) != EOF )
23
22
count ++ ;
24
-
25
23
return (count < PAGEBREAK ) ? 1 : count / PAGEBREAK ;
26
24
}
27
25
@@ -34,26 +32,26 @@ void printcover(char *s, int n)
34
32
printf ("Page count: %i\n" , n );
35
33
printf ("************************\n" );
36
34
37
- for (i = 4 ; i <= (PAGEBREAK / LINE ); ++ i )
35
+ for (i = 4 ; i <= (PAGEBREAK / LINE ); ++ i ) /* i = 4 to skip above lines */
38
36
printf ("\n" );
39
37
}
40
38
41
39
int main (int argc , char * argv [])
42
40
{
43
41
FILE * fp ;
44
42
char * prog = argv [0 ];
45
- int pages ;
43
+ int pages , c ;
46
44
47
45
while (-- argc > 0 )
48
46
if ((fp = fopen (* ++ argv , "r" )) == NULL ) {
49
47
fprintf (stderr , "%s: can't open %s\n" , prog , * argv );
50
48
exit (EXIT_FAILURE );
51
49
} else {
52
50
pages = pagecount (fp );
53
- rewind (fp ); /* rewind the input stream */
51
+ rewind (fp ); /* rewind input stream */
54
52
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 );
57
55
fclose (fp );
58
56
}
59
57
exit (EXIT_SUCCESS );
0 commit comments