文を読み取り、文の単語数を出力するプログラムを作成する必要があります。プログラムは完了しましたが、問題は、プログラムが単語間のスペースを文字としてカウントしていることです。これらのスペースを省略して、文字列内の単語数だけを表示するにはどうすればよいですか? ある種のループが必要だと思っていましたが、それを実行する方法がわかりません。
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#define pause system("pause")
main() {
char mystring[155];
int counter = 0;
printf("Enter your name: ");
scanf("%[^\t\n]", &mystring);
printf("Your name is %s\n", mystring);
// find out the number of characters in the string
counter = strlen(mystring);
printf("There are %i words in the sentence. \n", counter);
// find out how many WORDS are in the sentence. Omit spaces
pause;
} // end of main