/* * CHARCOUNT -- count the number of characters in the input * Note: this is a program crafted to show a static local variable * * Usage: charcount * * Inputs: a file * Output: number of characters in input * Exit Code: EXIT_SUCCESS (0) because all goes well * * written for ECS 030, Fall 2015 * * Matt Bishop, Oct. 16, 2015 * original program written */ #include #include /* * function to count number of times it has been called * also prints its argument as a char */ int func1(int c) { static int callcount = 0; /* number of times called */ /* called once more */ callcount++; /* print the argument */ putchar(c); /* say how many times it was called */ return(callcount); } /* * main routine */ int main(void) { int ch; /* input character */ /* * loop through file contents, printing each character * and the number of characters read so far */ while((ch = getchar()) != EOF) printf("-- %d chars printed\n", func1(ch)); /* * it's all over now */ return(0); }