Pages: [1]   Go Down
Author Topic: CharAt()  (Read 797 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My IDE is not recognising
Feel free to elaborate and provide more details.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 56
Posts: 2983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Strings are evil.  smiley-wink

Code:
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);
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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

What are/were you trying to accomplish?
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 56
Posts: 2983
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The variable named pointer is not a pointer. Lousy choice of names.
Agreed, but "hey, it's his code"
Logged

Pages: [1]   Go Up
Jump to: