My program is

```
#include <iostream>

char * grabNumber ( char * begin )
{
    // Interpret *begin as the start of a double and add the characters to a
    // string retstr

    char * begincpy = begin;
    int foundDot = 0;
    while ((*begin >= '0' && *begin  <= '9') || *begin == '.')
    {
        if (*begin == '.')
        {
            if (foundDot == 0) foundDot = 1;
            else break;
        }
        ++begin;
    }
    long n = begin - begincpy; // # of characters parsed
    char * retstr = malloc(sizeof(char) * (n + 1)); // string to be returned
    for (long k = 0; k < n; ++k) retstr[k] = *begincpy++;
    retstr[n] = '\0';
    return retstr;
}

int main()
{
   char str [] = "abc3.14def";
   std::cout << grabNumber(str+3); // should print "3.14"
   return 0;
}

```

and the errors I'm getting are

> 
> Line 20: warning: incompatible implicit declaration of built-in
>  function 'malloc' Line 21: error: 'for' loop initial declaration used
>  outside C99 mode
> 
> 
> 

corresponding to the 2 lines 

```
    char * retstr = malloc(sizeof(char) * (n + 1)); // string to be returned
    for (long k = 0; k < n; ++k) retstr[k] = *begincpy++;

```

See: <http://codepad.org/c2tNGFEo>

Also, is there a way that I can cut down on the redundancy of my algorithm, because it's checking for a `.` twice in each iteration of the `while` loop, and yet I can't think of a cleaner way to handle the fact that I need to stop the loop if we've run into a second `.`