Sure. But before I do that. There are some far more important things that you need to learn.
First, when you declare a pointer without assigning it to memory that has been properly allocated, either statically or dynamically, it is undefined behavior to dereference it. And you definitely should not be trying to write to the address it points to, as you do when you pass str to the gets function.
Second, never use gets. It doesn't allow you to set any kind of limit on how many characters will be read. So the user can just type and type to his hearts content, and gets will store it all, even if there is not enough memory allocated in the specified buffer. Use fgets instead.
Third, the return value of main is an int. Your compiler may accept void, but it is not proper C.
On to your question. For the time being, we will assume the rules above had not been grossly violated, and that str points to a properly allocated buffer in memory.
ptr=str;
That assigns ptr to point to the same place as str, which is the first character of the sentence that the user entered.
*ptr!='\0';
In C, strings are zero terminated. When we want to pass strings around, we just pass a pointer to the beginning of them. This pointer does not contain information about the length of the string. We find the end by incrementing forward until we get to a zero. The above statement is checking for that zero.
ptr++
Pretty basic. This advances the pointer to point to the next character.
if (*ptr==' ')
This is checking if the character pointed to is a space.
All together, what that loop does is scan through the sentence, one character at a time, counting the number of spaces. The intent being to use that to figure out the number of words. The assumption of course being that there is precisely one space between each word, therefore the number of spaces is one less than the number of words.
Here's what the code should look like if you don't want to violate the rules I gave at the beginning:
int main()
{
const int MAX_SENTENCE = 200;
char str[MAX_SENTENCE + 1];
char *ptr;
int wc=0;
clrscr()
printf("\n enter a sentence");
fgets(str, MAX_SENTENCE, stdin);
for(ptr=str; *ptr !='\0'; ptr++)
{
if(*ptr==' ')
{
wc++;
}
}
wc++;
printf("\n no of words=%d",wc);
getch();
return 0;
}