title: Using scanf to accept user input
body: <p>gcc 4.4.2</p>
  
  <p>I was reading an article about scanf. I personally have never checked the return code of a scanf.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
    char buf[64];
    if(1 == scanf("%63s", buf))
    {
      printf("Hello %s\n", buf);
    }
    else
    {
      fprintf(stderr, "Input error.\n");
    }
    return 0;
  }
  </code></pre>
  
  <p>I am just wondering what other techniques experienced programmers do when they use scanf when they want to get user input? Or do they use another function or write their own?</p>
  
  <p>Thanks for any suggestions,</p>
  
  <p>EDIT =========</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      char input_buf[64] = {0};
      char data[64] = {0};
  
      printf("Enter something: ");
      while( fgets(input_buf, sizeof(input_buf), stdin) == NULL )
      {
      /* parse the input entered */
      sscanf(input_buf, "%s", data);
      }
  
      printf("Input [ %s ]\n", data);
  
      return 0;
  }
  </code></pre>
  
  <p>I think most programmers agree that scanf is bad, and most agree to use fgets and sscanf. However, I can use fgets to readin the input. However, if I don't know what the user will enter how do I know what to parse. For example, like if the user was to enter their address which would contain numbers and characters and in any order?</p>