Go Down

Topic: Programing question (Read 282 times) previous topic - next topic

Tom55

Hello, I'm trying to figure out a few things with Arduino hooked up to Parallax reader but got stuck on some code. Tried to look at Arduino help/reference doesn't give me much hope. I guess this is completely beginner inexperience not to say lack of knowledge and if anyone can spare a few minutes to clarify that for me, I would be grateful.
What is the difference between the following variable declarations:

First question:

---------------------------------------
String  keyCode;
String  accessList[NumberOfKeys];
char    code[10];
--------------------------------------
I can see two arrays have been allocated but what is basically confusing me is string and char. What is the difference between them?

Second question:
-------------------------------------
keyCode = code;
       keyCode = keyCode.substring(0,10);
-------------------------------------
What is happening here, keyCode variable has been assigned code value, why we need the next line of code with keyCode.substring(0,10)?


Thank you very much in advance,
Tom

Arrch


I can see two arrays have been allocated but what is basically confusing me is string and char. What is the difference between them?


String (note the capitalization) is a class that allows for dynamically sizable strings. While you can use it with the Arduino, it's not recommended because it can cause fragmented memory. Normally, that isn't an issue on machines with plenty of RAM available, but not with the Arduino. The "char" you are seeing is a c-style string (Again, note the lack of capitalization) which is just an array of characters that is terminated by a null character.

String
string

Quote
What is happening here


keyCode is being assigned to a substring (characters 0 to 10) of code.

Tom55


Go Up