This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

atoi problems

I am having problems getting atoi to work.

here is how I populate the comin[] array

do
        {
        comin[index] = (getchar());
        ++index;
        }
        while (index<=4);

later in the program I do the following:-

command = atoi(comin);

expecting to get a 4 digit number in command. comin is working fine - no problems. But command is always 0 (zero). I have tried quite a few things, but no luck. I did a search on the forum andd came up with this

http://www.keil.com/forum/docs/thread10470.asp

Anybody else had this problem or know a work around?

Parents
  • "... expecting to get a 4 digit number in command."

    Assuming 'index' is 0 upon entry, the loop iterates 5 times.

    "But command is always 0 (zero)."

    Are you NUL-terminating received digits to make 'comin[]' a proper string or are you relying on some other means of causing atoi() to stop?

Reply
  • "... expecting to get a 4 digit number in command."

    Assuming 'index' is 0 upon entry, the loop iterates 5 times.

    "But command is always 0 (zero)."

    Are you NUL-terminating received digits to make 'comin[]' a proper string or are you relying on some other means of causing atoi() to stop?

Children