All pastes #52348 Raw Edit

Mine

public text v1 · immutable
#52348 ·published 2006-04-30 07:52 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] != ' '){					//start counting from the index
	++i;						//move index up a space till we hit a ' '
	++j;						//increment secondary letter counter
	}
return(j);						//the size of the word we just counted is passed
}

void printwords(char string[]){
total = 0;						//so far no words 
j = 1;							//skip foreward at least one character regardless
for (i = 0; i < strlen(string); (i = i + j)) {
	if (wordlength(string, i) > 3)			//pass current string and pointer to wordcount function
		++total;
	j = 1;						//reset j before proceeding
	} 
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); //assignment says i gotta use a procedure so don't return a value
return (0);
}