I need to write a program that will read in a sentence and output the number of words in the sentence. I have the program done, but the problem is that my program is counting the spaces inbetween the words as characters. How do I omit those spaces and just display the number of words in the string? I was thinking I need some type of loop, but I don't know how to execute it.
#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