37 lines
964 B
C
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);
|
|
}
|
|
|
|
|
|
} |