Thisquestion checks how the interviewee is familiar with C/C++? I’m so bad atC/C++...intatoi(char * str) { int neg = 0; char * p = str; if (*p == ‘-’) { p++; neg = 1; } else if (*p == ‘+’) { p++; } int num = 0; while (*p != ‘\0’) { if (*p>=&#39;0&#39; && *p <= &#39;9&#39;) { num = num * 10 + (*p-’0’); } else { error(“illegal number”); } p++; } return num;}PS: I didn’t figure out how to tell a overflow problem easily.
共 1 个关于本帖的回复 最后回复于 2013-8-16 13:04