[ create a new paste ] login | about

Link: http://codepad.org/6WCHU7Y5    [ raw code | output | fork ]

C, pasted on Oct 30:
void main()
{
char *ch="-8mn66";
printf("%d",parseInt(ch));
}

int parseInt(char *ch)
{
    int temp=0,neg=0;
    while(*ch!=NULL)
    {
        if(temp==0&&*ch=='-')neg=1;
        if(*ch>='0'&&*ch<='9')
        {
            if(temp==0)
            {
                 temp=*ch-'0';
            }
            else
            {
                 temp*=10;
                 temp+=*ch-'0';
            }
        }
    ++ch;
    }
if(neg==1)temp*=-1;
    return temp;
}


Output:
1
-866


Create a new paste based on this one


Comments: