summaryrefslogtreecommitdiff
path: root/ch1/counter.c
blob: a1b99278db2a5ca20785d8c3ada67686bf1a6e7c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>

/* 
 * Count characters in input; 1st version 
 */
//main() {
//    long nc;
//
//    nc = 0;
//
//    while (getchar() != EOF)
//        ++nc;
//
//
//    printf("%ld\n", nc);
//}

/*
 * Count characters in input; 2nd version
 */
main() {
    long nc;


    for (nc = 0; getchar() != EOF; ++nc)
        ;

    printf("%ld\n", nc);
}