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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

4,054件の閲覧回数
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
ラベル(1)
0 件の賞賛
返信
2 返答(返信)

1,133件の閲覧回数
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 件の賞賛
返信

1,133件の閲覧回数
jprime
Contributor I
That did it!  Thank you.
0 件の賞賛
返信