Converting String Numbers to int... problems using atoi()  (parsing numbers from a string)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting String Numbers to int... problems using atoi()  (parsing numbers from a string)

3,577 Views
jprime
Contributor I
Hello,
 
I am helping one of our electrical engineers on a project for the MC9S08SH8CTJ.
 
I would like to pass commands to it from hyperterminal, but for some reason I am having problems using atoi() to convert the ascii character string into a number
 
Code:
int nThree = 0;char *cThree = "3";nThree = atoi(cThree);

 
 
after stepping through the code I can see that it is getting inside the following method in stdlib.c
 
Code:
unsigned long int _strtoul(LIBDEF_ConstStringPtr nptr, LIBDEF_StringPtr *endptr, int base, unsigned int len)

it enters this loop of the previously mentioned function:

Code:
if (base < 37) {    while (CheckCharWithBase(*nptr, base, &val)) {      CHECK_OVERFLOW(lsum, >, (ULONG_MAX - val) / base, ERANGE);      lsum = lsum * base + val;      ++nptr;      if (--len == 0) {        goto done; /*lint !e801 Use of goto is not deprecated */      }    } /* end while */  }

The value for "lsum" is 0, "base" here is 10, "val" is 3, and nptr is pointing to the ascii character "3".  When it does the check overflow, it ends up in another file RTSHC08.c in this block of code, and it does not proceed past the last line here.

Code:
static void _ENTER_BINARY_L(void) {  asm {        _PUSH_REGS        PSHX              ; // @i        PSHH#ifdef __HCS08__        LDHX 6,SP         ; // ra        PSHX        PSHH


 
The command window provides this error:

Error: Attempt to push or pop with SP out of allowed range

 

Please note that I am not really used to C, and I have spent much more time in VB.Net, Java, and C#.  I need to be able to parse integer strings before I can proceed to terminal commands.  Thanks for the help.
 


 
 
 
 
 


Message Edited by jprime on 2008-08-12 08:49 PM
Labels (1)
0 Kudos
Reply
2 Replies

656 Views
CompilerGuru
NXP Employee
NXP Employee
>Error: Attempt to push or pop with SP out of allowed range

means: increase the stack size in the prm file, sounds like it runs out of stack space.

(or use another atoi implementation (I think there have been some in the past in this forum), or recompile it with overflow checking disabled)

Daniel
0 Kudos
Reply

656 Views
jprime
Contributor I
That did it!  Thank you.
0 Kudos
Reply