This repository has been archived on 2020-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stupid-coding-files/wordhistogram.c
2020-12-08 09:40:09 +02:00

37 lines
964 B
C

#include <stdio.h>
#define IN 1
#define OUT 0
main () {
/*initialize the counting variables and array*/
int c, wl, state, i;
int wlarr[10];
/* zero out the array */
for (i=0; i<10; i++)
wlarr[i]=0;
/*take input*/
/*for (i=0; i<10; i++)
printf("On array element %d\n", i);*/
while ((c = getchar()) != EOF)
{
/*printf("state is %d\n", state);*/
if (state == OUT)
{
wlarr[i]=wl;
wl=0;
putchar('\n');
/*if you were out and a new char comes in, you're back in a word*/
state = IN;
}
if (state == IN);
putchar(c);
++wl;
if (c == ' ' || c =='\n' || c =='\t')
/*if there's a blank, newline or tab, you're out of a word*/
state = OUT;
printf("Word length is %d\n", wl);
}
}