Yet another question about strings to chars

Hey all,

Firstly, I have searched the forums and came up with some great paths which have led me here. I have also found a deeper appreciation for Jack hand(e)y… (thanks mods)

So, I have a task… Simple task that I’m going to use to write some information to the EEPROM. Now, without using everyone elses code, I wanted to tackle it myself. To test my ability to code and understand what I read, I came up with a simple test to make sure I can get it to work:

void setup() {
  Serial.begin(9600);
    int i = 0;
    String eeSETTINGS = "BLAH:BLAH:BLAH";
//The Settings will only ever take up the first 100 of the EEPROM, so they will always write over the first 100..
    while (i < 100){
      Serial.print(eeSETTINGS.charAt(i));
      Serial.print("\t");
      Serial.print((char)(eeSETTINGS.charAt(i)));
      Serial.println();
    //EEPROM.write(i, char eeSETTINGS.charAt(i));
    i++;
    };
}

So, the goal here is to print the first letter of the string… which is B, then a Tab, and then the number 66.
Eventually, the goal will be to write to EEProm address (i) the value 66.

The Result i’m getting is B B. It’s not making the conversion to 66.

I have tried a few examples of switching things toCharArray, but the examples i’ve tried, have yeilded all zeros… so i’m convinced I did that part wrong. But if i’m pulling the charAt, that should give me the char, so I don’t have to convert it to a char array.

Of course, I could be wrong on many levels, and by some dumb luck the fact I got this to compile is going to be the foundation of build 1.55.

Type cast (eeSETTINGS.charAt(i)) as an int.

String data = "ABCD";

void setup(){
  Serial.begin(9600);
  for(unsigned int i=0; i<4; i++)
  {
    Serial.print( data[i]);
    Serial.print("  ");
    Serial.println((int) data[i]);
  }
}

void loop() { 
}

Output:

A 65
B 66
C 67
D 68

Hazards,

You rock. Thanks, that is exactly all i needed.

~Doc