This is farily easy. Break it down into logical steps. [edit] You can do this one integer. [/edit]
Code:
long int count_words( char *s )
{
long int count = 0;
if( s != NULL )
{
while( s && isspace( *s ) ) s++;
while( *s )
{
while( s && !isspace( *s ) ) s++;
count++;
while( s && isspace( *s ) ) s++;
}
}
return count;
}
I usually don't do homework for people, but I'm feeling ... something. Anyway, you probably don't want to use this for the simple fact that you'll have to prove to your teacher that you know just what it is exactly that this does.
To expand that into pseudo code you can understand:
Code:
while not at the end of the string (you could use a counter)
while we have a space, move to the next place in the string
while we have don't have a space, move to the next place in the string
increment the word count
Quzah.