Pergunta de entrevista da empresa Garmin

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

Respostas da entrevista

Sigiloso

12 de out. de 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; }

Sigiloso

24 de set. de 2018

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