title: Check if entire array of characters in C are only numbers, return true if yes?
body: <p>I have a string array of numbers: </p>
  
  <pre><code>char numbers[5][10] = { "123456789", "0001234", "abc5xyz", "", "987654321" };
  </code></pre>
  
  <p>I pass this array to a function:</p>
  
  <pre><code>  for(i=0; i&lt;5; i++) {
       MyFNatoi(numbers[i], &amp;value);
       printf("array: '%s' int value: %d\n", numbers[i], value);
    }
  </code></pre>
  
  <p>In this function, how could I check if the entire string is only numbers and return true if so? So far all I have is:</p>
  
  <pre><code>MyFNatoi(char *numArray, int *value) {
  
      int i;
  
      for (i = 0; i &lt; 10; i++) {
          if (numArray[i] &gt; 47 &amp;&amp; numArray[i] &lt; 58) {
              printf("%c", numArray[i] - 0);
              // sscanf(p, "%d", &amp;value);
          }
      }
  }
  </code></pre>
  
  <p>And that just returns:</p>
  
  <pre><code>123456789array: '123456789' int value: -1217188485
  0001234array: '0001234' int value: -1217188485
  5array: 'abc5xyz' int value: -1217188485
  array: '' int value: -1217188485
  987654321array: '987654321' int value: -1217188485
  </code></pre>
  
  <p>I'm trying to get value variable to be the equivalent of the string. So if the string is <code>123456789</code>, <code>value</code> should be <code>123456789</code>. If it is <code>abc5xyz</code>, <code>value</code> should be <code>0</code>.</p>
  
  <p>So far it just converts the characters to a 0 and returns :(</p>
  
  <p><strong>full source</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  MyFNatoi(char *numArray, int *value) {
  
      int i;
  
      for (i = 0; i &lt; 10; i++) {
          if (numArray[i] &gt; 47 &amp;&amp; numArray[i] &lt; 58) {
              printf("%c", numArray[i] - 0);
              // sscanf(p, "%d", &amp;value);
          }
  
          // printf("%c", numArray[i]);
      }
  // printf("- ");
  }
  
  int main( ) {
  
        char numbers[5][10] = { "123456789", "0001234", "abc5xyz", "", "987654321" };
        int i, value;
  
        for(i=0; i&lt;5; i++) {
           MyFNatoi(numbers[i], &amp;value);
           printf("array: '%s' int value: %d\n", numbers[i], value);
        }
  
        return 0;
     }
  </code></pre>