z_archive/problem37/ProjectEuler37/main.cpp
// Truncates the number by 1 digit. If leftTruncate true, truncates from left. Otherwise from the right.
Truncates the number by 1 digit. If leftTruncate true, truncates from left. Otherwise from the right.
Truncates the number by 1 digit . If leftTruncate true truncates from left . Otherwise from the right .
static int truncate(int num, bool leftTruncate)
{
    char numString[14] = {};
    char * numStringPtr = numString;
    snprintf(numString, sizeof(numString), "%d", num);
    if (leftTruncate)
    {
        numStringPtr++;
    }
    else
    {
        char * ptr = numString;
        char * lastPtr = numString;
        while (*ptr)
        {
            ptr++;
            if (!*ptr)
            {
                *lastPtr = 0;
            }
            lastPtr = ptr;
        }
    }
    return atoi(numStringPtr);
}
static int truncate ( int num , bool leftTruncate ) { char numString [ 14 ] = { } ; char * numStringPtr = numString ; snprintf ( numString , sizeof ( numString ) , " " , num ) ; if ( leftTruncate ) { numStringPtr ++ ; } else { char * ptr = numString ; char * lastPtr = numString ; while ( * ptr ) { ptr ++ ; if ( ! * ptr ) { * lastPtr = 0 ; } lastPtr = ptr ; } } return atoi ( numStringPtr ) ; }
Truncates the number by 1 digit.
Truncates the number by 1 digit .