title: Simple C code not working
body: <p>I have written a simple code to check whether a given character is present in the string entered by the user but it doesn't seem to work.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  int main()
  {
      char a[20],b;
      int i,p=0,n;
      printf("Enter the string-");
      scanf("%s",a);
      printf("\nEnter the character-");
      scanf("%c",&amp;b);
      n=strlen(a);
      for(i=0;i&lt;n;i++)
      {
          if(a[i]==b)
          {
              printf("\ncharacter is present in string\n");
              p=1;
              break;
          }
      }
      if(p==0)
          printf("\nchracter is not present in string\n");
      return 0;
  }
  </code></pre>
  
  <p>The output I get is this: <a href="http://i58.tinypic.com/2gvnedt.png" rel="nofollow">http://i58.tinypic.com/2gvnedt.png</a></p>
  
  <p>I do not see what is wrong with the code. If I replace "scanf("%s",a);" with "gets(a);" it works fine. Why?</p>
  
  <p>Help is appreciated. Thanks!</p>