scan in words from i/o ``` int main(void){ int num_words = 0; // state == 0 if we’re looking for a new word // state == 1 if we’re currently reading through a word int state = 0; char input; int result = scanf(“%c”, &input); while (result == 1){ if ((input <= ‘Z’ && input >= ‘A’) || (input <= ‘z’ && input >= ‘a’)){ if(state == 0){ ++num_words; } } else { if (state == 1){ state = 0; } } result = scanf(“%c”, &input); } printf(“%d\n”, num_words); }

Tutorial 8 | Home