Google

  www.google.com
  www.google.com

Interview Question

Software Development Engineer Interview New York, NY

Convert string to integer like atoi in C

Answer

Interview Answer

1 Answer

0

int
myatoi(LPTSTR pszInt)
{
    int retval;
    TCHAR cSave;

    for (retval = 0; *pszInt; ++pszInt) {
        if ((cSave = (TCHAR) (*pszInt - TEXT('0'))) > (TCHAR) 9)
            break;

        retval = (int) (retval * 10 + (int) cSave);
    }
    return (retval);
}

Brycej on Oct 29, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.