All pastes #39478 Raw Edit

wouterrr

public c v1 · immutable
#39478 ·published 2006-02-01 14:13 UTC
rendered paste body
/* * Simple word counter... This program should print a horizontal histogram, the * vertical one is a bit harder to make... But hey, let's start simple : -). * * Exercise 1-13 */#include <stdio.h>#define SIZE 10int main() {        int ch, cnt, val, bool;        int nword[SIZE];        for ( cnt = 0; cnt < SIZE; ++cnt ) {                nword[cnt] = 0;        }        cnt = val = 0;        while ( ( ch = getchar() ) != EOF ) {                if ( ch == ' ' || ch == '\n' || ch == '\t' ) {                        ++nword[val-1];                        cnt = 0;                }                else {                         val = ++cnt;                }        }                val = cnt = 0;        bool = 1;        while (bool) {                if ( val == 0 ) {                        printf("Length %d: ", cnt+1);                }                if ( val < nword[cnt] ) {                        printf("*");                        ++val;                }                if ( val == nword[cnt] ) {                        ++cnt;                        val = 0;                        printf("\n");                }                if ( cnt == SIZE ) {                        bool = 0;                }        }        return 0;}