title: Find a sum of numbers in a given string
body: <p>I have to find the sum of the numbers in a given string
  For example for "a11b3" the amount will be refunded 14 because (11+3=14)
  I wrote the following code but it does not work for me in any situation, how can I optimize it?</p>
  
  <pre><code>int SumStr(char* str)
  {
      int i, sum = 0, digit = 0;
      while (*str)
      {
          digit = 0;
          while (*str &gt;= '0' &amp;&amp; *str &lt;= '9' &amp;&amp; *str)
          {
              digit = digit * 10 + (*str - '0');
              str++;
          }
          if (digit &gt; 0)
              sum += digit;
          str++;
      }
      return sum;
  }
  </code></pre>