Go Down

Topic: CharAt() (Read 1 time) previous topic - next topic

ianmgreen

My IDE is not recognising the string.charAt command,

It isnt even highlighting when using example code from the arduino site.
I have seen this issue raised before with no clear answer?

Code: [Select]
String test;


void setup()
{
Serial.begin(9600);
String test = "23456";
}

void loop()
{
char pointer = test.charAt(2);
Serial.print(pointer);
delay(1000);
}



Any help is great thanks

Arrch


My IDE is not recognising

Feel free to elaborate and provide more details.

ianmgreen

sorry about that,

The arduino IDE does not highlight the string.charAt() command in orange, and does not act upon it,

im trying to establish whether the code im using is missing something or whether my IDE is setup wrong somehow

Thanks again

michael_x

Strings are evil.  ;)

Code: [Select]
char test[] =  "23456";

void setup()
{
  Serial.begin(9600);
}
void loop()
{
 int i=0;
 while (i < strlen(test) )
 {  
    char pointer = test[i++];
    Serial.println(pointer);
    delay(1000);
 }
}

ianmgreen

thankyou muchly,

Ill have to alter my code a bit to remove the charat command and add in that bit but you have skipped ahead of me there which is lovely, im making a dialer and that bit of code does exactly what i was going to do in a far simpler manner.

Ta very much

Ian

PaulS

Code: [Select]
String test;
A global variable, with no initial value. Useless, but, hey, it's your code.

Code: [Select]
String test = "23456";
A local variable that immediately goes out of scope. Useless, but, hey, it's your code.

Code: [Select]
char pointer = test.charAt(2);
The variable named pointer is not a pointer. Lousy choice of names.

What are/were you trying to accomplish?

michael_x

Quote
The variable named pointer is not a pointer. Lousy choice of names.

Agreed, but "hey, it's his code"

Go Up