String to Integer (atoi)

Implement atoi to convert a string to an integer.

Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.

Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.

input cases:
pointer = NULL ==> 0
first character is not "+","-",digit ==> 0(better with a global flag)
second character is not digit ==> 0 
find non-digit while generating the result ==> stop and return the result before this non-digit
larger than 0x7fffffff ==> 0x7fffffff
smaller than 0x80000000 ==> 0x80000000

Step:
remove the prefixed spaces
check first character: +,-,digit, flag = '-'? 1:0
iterate: long long result = result * 10 + next_character - '0'
(check errors along)