#include <stdio.h>
#include <string.h>
int count_words(char str[], char *delimiter) {
if (str == "") {
return 0;
}
char *word = strtok(str, delimiter);
int count = 0;
while (word != NULL) {
count++;
word = strtok(NULL, delimiter);
}
return count;
}
int main(void)
{
char str[] = "c is a general purpose procedural programming language";
printf("%d", count_words(str, " "));
return 0;
}
/*
run:
8
*/