Find length of the string(excluding spaces)?
<pre><code>#include&lt;iostream.h&gt;
#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
#include&lt;string.h&gt;
void main()
{
clrscr();
char name[10];
char op;
int w, len;
cout&lt;&lt;"Menu\n1.Length of the string(with &amp; without spaces)\n" \\I have edited out the rest as it was irrelevant to my question
cin&gt;&gt;op;
switch(op)
{
case '1': cout&lt;&lt;"Enter a word";
          gets(name);
          w=strlen(name);
          cout&lt;&lt;"The length of the string including spaces is"&lt;&lt;w;
          for(int i=0;i!=w;++i)
          {
          if (name[i]!=' ')
          {
          len++;
          }
          }
    cout&lt;&lt;"Excluding spaces is\n"&lt;&lt;len;
}
getch();
}
</code></pre>

<p>I'm using Turbo C7 compiler for this program.
It displays including spaces value, but not excluding spaces.
Please correct the code if it's wrong.</p>