All pastes #594408 Raw Edit

Word Utility

public c v1 · immutable
#594408 ·published 2007-06-28 22:34 UTC
rendered paste body
#include <stdio.h>#define OUT 0#define IN  1int main(){	printf("HELLO! THIS IS A BETTER VERSION OF THE UNIX PROGRAM CALLED wc!\n");	printf("THIS PROGRAM TAKES THE ENTER KEY AS A CHARACTER SO EVERYTIME YOU PRESS ENTER IT WILL GIVE YOU A CHARACTER PLUS!\n");	printf("THIS IS THE FINAL VERSION OF THIS WORD UTILITY PROGRAM\n");	while(1)	{		int x, state, words, lines, tabs, chars, blanks, letters;		state = OUT;		words = lines = tabs = chars = blanks = letters = 0;			while((x = getchar()) != EOF)		{			++chars;			switch(x)			{			case ' ':				++blanks;			break;			case '\t':				++tabs;			break;			case '\n':				++lines;			break;			default:				++letters;			break;						}			if (x == ' ' || x == '\t' || x == '\n')				state = OUT;			else if (state == OUT)			{				state = IN;				++words;			}			}		printf("You have %d word(s)\n", words);		printf("You have %d letter(s)\n", letters);		printf("You have %d character(s) in total:\n", chars);		printf("You have %d line(s)\n", lines);		printf("You have %d tab(s)\n", tabs);		printf("You have %d blank(s)\n", blanks);	}}