title: C program to count words in a given string/sentence?
body: <p>I want to count the words in a given string by counting the spaces between them. Here's the code that i've tried.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;string.h&gt;
  main()
  {
   int t,i,b=1;
   char a[100];
   printf("Enter a sentence: ");
   gets(a);
   t=strlen(a);
   for(i=0;a[i]!='\0';i++)
   {
        if(a[i]=' ')
        {
             b++;
        }
   }
   printf("The number of words in the above sentence are %d",b);
   getch();
  }
  </code></pre>
  
  <p>But i am unable to get the output. I keep getting wrong number of words. </p>
  
  <p>Thanks. :D</p>