Implement your own atoi


atoi Parses the C-string str interpreting its content as an integral number, which is returned as a value of type int.

int atoi (const char * str);

Replicating the exact characteristics of atoi is pretty difficult from memory so I see this as question which is ripe for discussion about how you will handle input like whitespace, non base-10 characters, a leading sign character. You may also want discuss handling values which overflow int.

int atoi(const char* pInput)
{
    if (NULL == pInput || !(*pInput))
        return 0;
    
    int index = 0;
    if(pInput[0] == '-' || pInput[0] == '+')
    {
        index = 1;
    }
    
    int value = 0;
    for(; index < strlen(pInput); index++ )
    {
        if( pInput[index] >= '0' && pInput[index] <= '9' )
        {
            value = value * 10 + pInput[index] - '0';
        }
    }
    
    bool isNegative = pInput[0] == '-';
    if(isNegative)
    {
        value = -value;
    }
    
    return value;
}