title: What is the difference between sscanf or atoi to convert a string to an integer?
body: <p>gcc 4.4.4 c89</p>
  
  <p>What is better to convert a string to an integer value.</p>
  
  <p>I have tried 2 different methods atoi and sscanf. Both work as expected.</p>
  
  <pre><code>char digits[3] = "34";
  int device_num = 0;
  
  if(sscanf(digits, "%d", &amp;device_num) == EOF) {
      fprintf(stderr, "WARNING: Incorrect value for device\n");
      return FALSE;
  }
  </code></pre>
  
  <p>or using atoi</p>
  
  <pre><code>device_num = atoi(digits);
  </code></pre>
  
  <p>I was thinking that the sscanf would be better as you can check for errors. However, atoi doesn't doing any checking.</p>