All pastes #52349 Raw Edit

Something

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

int wordlength(char sentence[], int i){
while ((sentence[i] != ' ') && (sentence[i] != '/n')){					//start counting from the index
	++i;						//move index up a space till we hit a ' '
	++j;
	printf("%c is the character\n",sentence[i]);						//increment secondary letter counter
	}
return(j);						//the size of the word we just counted is passed
}

void printwords(char sentence[]){

total = 0;						//so far no words 
j = 1;							//skip foreward at least one character

for (i = 0; i < strlen(sentence); (i = i + j)) {
	if (wordlength(sentence, 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);
}