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

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

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


From: Eric Fu
Subject: [avr-gcc-list] Problem with atol() and strtol()
Date: Thu, 10 Jun 2004 21:07:54 +1000

I'm using WinAVR 20040404.

dword is define as   typedef unsigned long    dword;

The fact that atoi works and atol() and strtol() don't confuse me. 

The following is the repeat of my last email:

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.
      {        //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 for 
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.


Eric Fu

reply via email to

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