title: Count number of spaces and words in an integer
body: <p>I'm trying to write a C program that counts the number of words and spaces in a given string. Here's what I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
    int i, spaces;
    char a[30];
    printf("enter the string");
    scanf("%s", a);
    for(i=0 ; a[0]!="\0" ; i++
      {
        if (a[i]=' ')
          {
            spaces++;
          }
      }
    printf("Number of spaces is %d", spaces);
    printf("Number of words is %d", spaces + 1);
  }
  </code></pre>
  
  <p>It gives me a weird error at 9:19. Help would be much appreciated.</p>
  
  <p>Updated:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   int main()
   {
     int i,spaces;
     char a[100];
     printf("enter the string\n");
     scanf("%s",a);
     for(i=0 ; a[i]!='\0' ; i++)
       {
         if (a[i]==' ')
       {
       spaces++;
       }
       }
     printf("the no. of spaces in the string is %d\n",spaces);
     printf("the no. of words in the string is %d\n",spaces+1);
   }
  </code></pre>
  
  <p>Now doesn't metter what string I input, it'll say there's 0 spaces and 1 word. Why is this?</p>