Section 1.5.2 Character Counting2


#include <stdio.h>
/* count characters in input; 2nd version */
    double nc;
    for (nc = 0; getchar() != EOF; ++nc)
    printf("%.0f\n", nc);
Run this


In this program we are going to count the number of characters present in the input. The program does the counting by setting nc to 0 in the beginning. As the program enters for loop condition (nc = 0; getchar() != EOF; ++nc). When nc hits end of the document it prints the number of characters in the file.

This document was updated on 31 Dec of 16

Comments by Disqus