Garmin Interview Question

Write an ascii to int converter function on a white board.

Interview Answers

Anonymous

Oct 12, 2016

int myAtoi(char *str) { int res = 0; // Initialize result // Iterate through all characters of input string and // update result for (int i = 0; str[i] != '\0'; ++i) res = res*10 + str[i] - '0'; // return result. return res; }

1

Anonymous

Sep 24, 2018

The above answer ignores sign. I would start by checking for '-' and deciding if the answer should be positive or negative.