mp-utils/src/wc.c

68 lines
862 B
C
Raw Normal View History

#include "common.h"
enum {
LINES,
WORDS,
BYTES
};
int* count_values(FILE *fp)
{
static int count[3] = {0};
char in_word, c;
in_word = c = 0;
while((c = getc(fp)) != EOF)
if(in_word)
switch(c)
{
case '\n':
count[LINES]++, count[BYTES]++;
in_word = 0;
break;
case ' ':
in_word = 0;
count[BYTES]++;
break;
case '\t':
in_word = 0;
count[BYTES]++;
break;
default:
count[BYTES]++;
break;
}
else
switch(c)
{
case '\n':
count[LINES]++, count[BYTES]++;
break;
case ' ':
count[BYTES]++;
break;
case '\t':
count[BYTES]++;
break;
default:
count[WORDS]++, count[BYTES]++;
in_word = 1;
break;
}
return count;
}
int main(int argc, char **argv)
{
return 0;
err:
}