title: String has contents even though there is no input from user
body: <p>I am trying to "trap" keyboard inputs from user, meaning the code will prevent them from entering certain characters, which in this case prevents the input of numbers and special characters.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  char buffer[30];
  void in_text();
  
  int main(void)
  {
  in_text();
  printf ("\nThe string you entered is: %s", buffer);
  
      return 0;
  }
  
  
  void in_text(void)
  {
  char buffe[30]; 
  char c1;
  int x = 0, hit = 0;
  
  printf("Enter string: ");
  
  
  while (hit!=1)
  {   
      c1 = getch();
  
      if (c1=='\b' &amp;&amp; x!=0)
      {
          buffe[--x] = '\0';
          printf ("\b \b");
      }
  
      if (isalpha(c1) || isspace(c1) &amp;&amp; c1!='\r') 
      {
          buffe[x++] = c1;
          buffe[x+1] = '\0';
          printf("%c", c1);
      }   
  
      if (c1=='\r' &amp;&amp; strlen(buffe)==0)
      {
          buffe[x+1] = '\0';
      }   
      else if (c1=='\r' &amp;&amp; strlen(buffe)&gt;1)
      {
          printf ("%d", strlen(buffe));
          printf ("\n%s", buffe);
          hit = 1;
      }   
      else{
      }       
  }
  
  strcpy(buffer, buffe);
  
  return 1;
  }
  </code></pre>
  
  <p>This code tries to mimic the <code>scanf</code> input style that one can see and press backspace to delete a previously entered character. I want to "trap" the enter key such that when the user presses "Enter", the program checks if the current string (buffe) contains at least one valid character and that when the program checks for input and finds out that the user pressed the Enter key and the string does not contain anything, the loop continues.</p>
  
  <p>The problem with my code is that when I do press Enter, immediately after the program starts, the <code>strlen</code> function returns a value larger than 0, which I assume is not normal since there is no input from the user yet, aside from that "Enter" key that the user pressed.</p>
  
  <p>Any thoughts on this?</p>