avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Problem with atol() and strtol()


From: Eric Fu
Subject: Re: [avr-gcc-list] Problem with atol() and strtol()
Date: Thu, 10 Jun 2004 08:47:44 +1000

The offending portion of the code is:

byte volatile InputChangeFlag = 1; // when !0, input caption should be sent
out
dword TargetFreq;
...


if(ReadSerialPort0(uart0.InBuf,&uart0.NumCharsRead,2) == READ_COMPLETED)
     {
      if(uart0.NumCharsRead >= 7) //Speed  is in range of 0 to 35,000.
Maximum 4 digits
      {        //including CR
       TransmitString0(ErrCaption);
       TransmitUART0( '\r');
      }
      else if(uart0.NumCharsRead != 1)
      {
       //TargetFreq = atol(uart0.InBuf);  // Doesn't work!
       //TargetFreq = strtol(uart0.InBuf, (byte **)NULL, 10);   // Doesn't
work!
       TargetFreq = atoi(uart0.InBuf);  // Always works
       //TargetFreq = AsciiToLong(uart0.InBuf, uart0.NumCharsRead-1); // my
own version of the converter always works
       ultoa(TargetFreq,uart0.OutBuf,10);// the ASCII string will be
terminated with '\0'
       //WriteUART0(3,uart0.OutBuf);
       TransmitString0(uart0.OutBuf);
       TransmitUART0( '\r');
       MonParam.Index = KP;
      }
      else
       MonParam.Index = KP;
      InputChangeFlag = 1; // update caption at next entry
      uart0.NumCharsRead = 0; // read from the start of the buffer again foe
next read
     }

The debugging tool shows that uart0.InBuf[] always contain valid ASCII
digits. However, atol() and strtol() never work. (Always return 0). atoi()
and my own version of the converter always works. Note: of course,atoi()
works if the digits are int size.

Thanks.

Eric Fu

----- Original Message ----- 
From: "E. Weddington" <address@hidden>
To: <address@hidden>; "Eric Fu" <address@hidden>
Sent: Thursday, June 10, 2004 2:15 AM
Subject: Re: [avr-gcc-list] Problem with atol() and strtol()


> On 9 Jun 2004 at 20:55, Eric Fu wrote:
>
> > Hi,
> >
> > I'm trying to convert a ASCII string from Hyper terminal to a long
integer. Both
> > atol() and strtol() return only 0 with any  ASCII input. However, atoi()
always
> > works. I can't figure out why. I'm using WinAVR 20040404 with ATmeg16.
Could any
> > one give me an advice on that please.
> >
>
> You'll have to post the offending code.
> Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]