All pastes #52347 Raw Edit

Miscellany

public text v1 · immutable
#52347 ·published 2006-04-30 07:46 UTC
rendered paste body
#include <stdio.h>
#include <string.h>
char sentence[1000];
int i;
int j;
int total;

int wordlength(char line[], int i){
while (line[i] != ' '){
	++i;
	++j;
	}
return(j);
}

void printwords(char string[]){
total = 0;
j = 1;
for (i = 0; i < strlen(string); (i = i + j)) {
	if (wordlength(string, i) > 3)
		++total;
	j = 1;
	} 
printf("There are %d words in that sentence.\n",total);
return;
}

int main(){
printf("Input a sentence and I'll count the words.\n");
printf("A word is at least 4 characters long.\n");
fgets(sentence,sizeof(sentence),stdin);
printwords(sentence);
return (0);
}