title: Pass by reference to a recursive function
body: <pre><code>#include &lt;stdio.h&gt;
  
  void word(char a[100], int i, int *max, int *c)
  {
      printf("%d  %d", max , c);
      int length = 0;
      while (i &lt; strlen(a) &amp;&amp; a[i] != ' ')
      {
          length++;
          //printf("%c\n", a[i]);
          i++;
      }
      if (a[i] == ' ' &amp;&amp; i &lt; strlen(a))
      {
          c++;
          if (length &gt; max)
              max = length;
          //printf("%d\n%d", max, c);    
          word(a, i + 1, max, c);
      }
  }
  
  void main()
  {
      char a[100];
      int max = 0, j, i = 0, c = 0;
      scanf("%[^\n]s", &amp;a);
      word(a, 0, &amp;max, &amp;c);
      printf("%d\n%d", c, max);
  }
  </code></pre>
  
  <p><strong>GIVEN PROBLEM</strong>: <em>Given a String with spaces, write an algorithm and a C program to count the number of words in it and length of the longest word. For example, if the input string is ‘I love programming’ then the number of words is three and length of the longest string is 11.</em></p>
  
  <p>I am facing problem while passing the variables <code>max</code> and <code>c</code> by reference in the recursive function <code>word()</code>. The variables are not being passed properly. i wish the variables to be passed by reference recursively so as to update their value with each recursive call. I am a newbie to stackoverflow, so please correct me wherever I have made mistakes.</p>