Using functions itoa, and dtostrf

Status
Not open for further replies.

JohnDH

Member
I do an #include <stdlib.h>, but get 'Not declared in zone' error messages for these functions. Arduino says that these functions are OK, so is this a Teensy 3.1 issue?
 
I use iota without including <stdlib.h> with teensy 3.1 and teensydunio 1.21 installed - something else is wrong

Code:
void setup()
{
  Serial.begin(115200);
  while(!Serial && millis() < 5000) ; // wait for terminal to start or 5s ...
  
  char tempText[10] {0};
  int tempInt = 0;
  int maxInts = 100;
  
  Serial.println("Int to ascii using itoa");
  Serial.println("Dec\tHex\tOct");
  for (int n = 0 ; n < maxInts ; n++ )
  {
    itoa(n, tempText, 10); // decimal
    strcat(tempText, "\t"); // just to show other std library C functions also work without includes
    Serial.print(tempText);
    itoa(n, tempText, 16); // Hex
    strcat(tempText, "\t"); 
    Serial.print(tempText);
    itoa(n, tempText, 8); // Octal
    strcat(tempText, "\n"); 
    Serial.print(tempText);
  }

}

void loop()
{
}
 
I tried, but could not reproduce the problem. Of course, since the actual code wasn't posted, I had to make something up with "do an #include <stdlib.h>". See this screenshot:

sc.png
(click for full size)
 
I found that 'dtostrf' requires #include <math.h> Also I was including a .cpp file (A no-no for Arduino). With that changed to a .ino file, then everything worked.
Thanks All
 
Status
Not open for further replies.
Back
Top