Problems with AVR Library Routines

Hello!

I am using Arduino 0010 Alpha and I tried to write a program using the
"atoi()" library function like this:

char cmd[16];
:
:
int pin;
pin = atoi(&cmd[1]);

I get an error message stating: "undefined reference to 'atoi(char*)' "
Do I need to import a library or #include a file?

I wrote my own atoi() function and the program compiled and ran correctly.
However, I would prefer to use the library function if I can.

Thanks,
Eric

I think atio is in <stdlib.h> , try add that include to your sketch.

mem,

Thanks for your suggestion, but I get the same error whether I #include <stdlib.h> or not.

Regards,
Eric

Eric, the sketch below compiles for me without errors in version 010

void setup()                  
{
}

void loop()                    
{
   char cmd[16];
   int pin;
   pin = atoi(&cmd[1]); 
}

BTW, stdlib.h must be included automatically when the arduino build includes the invisible "WProgram.h", sorry for the confusion there.

Try build 010 if you are not already using it. If you are, try posting a little more of the sketch that has the problem.

mem,

I think I found it! It seems that multi-line comments don't quite work.

I "removed" my atoi() function by commenting it out, like this example,
which does not compile:

void setup()                  
{
}

void loop()                    
{
   char cmd[16];
   int pin;
   pin = atoi(&cmd[1]); 
} 

/*
// convert string to numeric value
int atoi(char *array) {
}
*/

Using single-line comments in the same code compiles correctly, though:

void setup()                  
{
}

void loop()                    
{
   char cmd[16];
   int pin;
   pin = atoi(&cmd[1]); 
} 

// convert string to numeric value
//int atoi(char *array) {
//}

Is this a bug in the IDE?

Regards,
Eric

There is a known bug in how the Arduino IDE handles comments when parsing sketches prior to compiling. It looks like your code fell foul of that.

Glad to hear you got it working.