/* * digitcounter * Selftest Problem4 * Chapter 6 * John Stile * Purpose: Write a program named digitcounter.c * that reads from input and determins the * number of digits in the input, and * outputs the result. */ #include int main(void) // header for function main { int digits=1; // declare and initialize int variable digits while( (getchar() != EOF ) ) // get character from stdin // until we reach end of file. { digits=digits+1; // add 1 to the digit counter. } // run while expression again // Loop has ended, we have counted all chars input. printf("The number of digits input: %d\n", digits); // print result return 0; // return 0 to calling program }