Word Counter
C
Medium
2 views
Problem Description
Count how many words are in a sentence. Separate words with a space. Handle multiple spaces. Ignore leading/trailing spaces.
Official Solution
#include <stdio.h>
int main() {
char str[200];
int i;
int count = 0;
printf("Enter a sentence: ");
fgets(str, sizeof(str), stdin);
for (i = 0; str[i] != '