Desperate error :-( ....need help !

Hello all,

Need some help on this part of code I have error on the two ligne I put in comment

In function 'void loop()':

353: error: invalid types 'char [(((sizetype)(((ssizetype)myStringLength) + -1)) + 1)][char*(const char*, int)]' for array subscript
invalid types 'char [(((sizetype)(((ssizetype)myStringLength) + -1)) + 1)][char*(const char*, int)]' for array subscript

This is return of submit for the embedded server inside the board and the purpose is to same the new MAC inside the EEPROM

//****************************************MAC adress of this board *************************
char mystring[]="MC0=";
String macStr="";
String MAC;
for (int index = 48; index < 54; index++)// 48= ASCII du Zero en decimal
{
mystring[2]= char(index);// Increment the index (at position 2) value in the string
Serial.print(mystring); // print name of field with index
charsRead=finder.getString(mystring ,"&", filenameValue, 5);// seach for next indexed MCx value
if(charsRead>0) // got it !
{
filenameValue[charsRead]='\0';// read the value
Serial.println(filenameValue); //print the value
macStr = macStr + filenameValue; // concaten the result
Serial.println ("macStrc = "+macStr);
}
}
String myString = macStr ;
int myStringLength = macStr.length()+1;
char myChar[myStringLength]; // create array
char MACchar;
myString.toCharArray(myChar,myStringLength); // insert value in the array
for (int Index=0 ; Index<macStr.length();Index++)
{
if ((int(myChar[Index])>0) && (int(myChar[Index])<128))
{
Serial.println (int(myChar[Index]),HEX);
// MACchar = char(int(myChar[index]);
}
else
{
Serial.println (int(myChar[Index])+256,HEX);
// MACchar = char(int(myChar[index]+256);
}
MAC= MAC + String(MACchar);
}
Serial.println ("MAC= " +MAC);
//Update_String2EEPROM (MAC,9); // MAC is at position 9 in EEPROM

Hi,
To help you we need your complete code.

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

If it is too big then attach the ino file to your post.
Attach facility is on REPLY not QUICK REPLY.

Hope to help.....Tom.. :slight_smile:

You REALLY need to decide if you are going to work with strings (preferred) or Strings. Do NOT try to mix and match and convert back and forth.

myString and mystring are not good names. There is a reason that you are collecting data in a string/String. Name the variable appropriately.

You need to post ALL of your code, so we can replicate the problem, and see the offending line highlighted. With just snippets, we have no idea which line is line 333.

The code is 95% of my board on compiling now, very big :frowning:

the error are on commented lign

MACchar = char(int(myChar[index]);

Globally the purpose is :

I receive "AA" in mytring

I Get string "A" in myChar[index] and want to transform to ASCII code 41 then get the caracter A to store in EEPROM

MACchar = char(int(myChar[index]);

What's with all the casting? myChar suggests that it is an array of characters. Casting characters to ints and back to chars to store in a char variable is a while lot of crap.

I Get string "A" in myChar[index]

Nonsense. You get the character 'A'. You do NOT need to convert that to 41 so you can convert it back to 'A'.

at beginning I declare MAC as this :

byte mac[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; // RESERVED MAC ADDRESS

I already wrote the MAC in EEPROM like this :

String MAC = String((char*)mac); // convert to char then string
Serial.println ("MAC= " +MAC);
//Serial.print ("Length = ");
//Serial.println(MAC.length());
MAC=MAC.substring(0,MAC.length()-1); // remove extra 0 form the string

Write_String2EEPROM (MAC,9); // MAC is at position 9 in EEPROM

I can read back with this :

// -----------------------------------------Mac adress
String MaMAC=Read_String2EEPROM(9);
Serial.println ("MAC read = "+ MaMAC);
char Mytable[MaMAC.length()+1];
MaMAC.toCharArray(Mytable,MaMAC.length()+1);

for (int Index=0 ; Index<MaMAC.length();Index++)
{
// Serial.print ("Read Value =");
// Serial.println (Mytable[Index]);

if ((int(Mytable[Index])>0) && (int(Mytable[Index])<128))
{
Serial.println (int(Mytable[Index]),HEX);
}
else
{
Serial.println (int(Mytable[Index])+256,HEX);
}
}
Serial.println();

but now I still have to pass to Mac array.......

PaulS:

MACchar = char(int(myChar[index]);

What's with all the casting? myChar suggests that it is an array of characters. Casting characters to ints and back to chars to store in a char variable is a while lot of crap.
Nonsense. You get the character 'A'. You do NOT need to convert that to 41 so you can convert it back to 'A'.

Yes, I am not very good in this language and should improve for sure

What I want is to transform the "AA" received as string I.E. 4141 to 0xAA and store this in EEPROM

any help will be highly appreciate :wink:

String MAC = String((char*)mac); // convert to char then string

That is NOT what that line does.

MAC=MAC.substring(0,MAC.length()-1); // remove extra 0 form the string

Why? Strings wrap strings that are NULL terminated. Not writing the NULL to EEPROM is one thing. Removing it from the String is another (stupid) thing.

if ((int(Mytable[Index])>0) && (int(Mytable[Index])<128))

The cast to int is completely unnecessary.

There was NO reason to convert the byte array to a String to store in EEPROM. It's 6 bytes. Just store them one at a time in EEPROM, to consecutive addresses. You are making the process FAR more difficult than it needs to be. Reading the 6 bytes back, and storing in a byte array will then be trivial, with no wasted memory and no useless casts.

Thanks PAULS,

I undestand I am wrong and this code is heavy for nothing

what did you suggest ?

what did you suggest ?

For saving:

for(byte b=0; b<6; b++)
{
   EEPROM.write(b+9, mac[b]);
}

For reading:

for(byte b=0; b<6; b++)
{
   mac[b] = EEPROM.read(9+b);
}

8 lines of code, instead of all that complicated malarkey you have.

PaulS:
For saving:

for(byte b=0; b<6; b++)

{
  EEPROM.write(b+9, mac[b]);
}




For reading:


for(byte b=0; b<6; b++)
{
  mac[b] = EEPROM.read(9+b);
}




8 lines of code, instead of all that complicated malarkey you have.

::slight_smile: there is some that know how to and the other !

:sob: I am not in the first case !

And how to transform my AA string to the AA byte then ?

And how to transform my AA string to the AA byte then ?

Is that an "AA" string or an "AA" String? Strings and strings are not the same thing.

Consider that an 'A' has a value as an int, in base 10, of 'A' - 'A' + 10, or 10.

B would then have a value of 'B' - 'A' + 10, or 11, C 12, etc.

Obviously, the digits '0' to '9' have different values ('9' - '0' is 9, for instance).

Once you know the integer value for each digit, multiply the first by 16 and add the second.

Of, if you have a string, the strtol() function is useful. If you have a String, shame on you.