Hi All,
How to convert a char into byte ?
I've tried (without so much hope) the byte() function, but received the below error message :
cast from 'char*' to 'byte' loses precision
How can I escape this ?
Thanks
Hi All,
How to convert a char into byte ?
I've tried (without so much hope) the byte() function, but received the below error message :
cast from 'char*' to 'byte' loses precision
How can I escape this ?
Thanks
char is default a signed type.
byte is defined as 'unsigned char'
but you are using char* in this case not char ( error message ), one is an address to data and the other is... data
Hint:
char is a byte literally not the type 'byte'. 256 different values, most if not all arduinos have more than 256 bytes ram. A pointer will not fit into a char
You're true, not noticed that.
Where can I find some litterature in char* or whatever* type. I need some basic learning on that part of variables usage apparently...
Pointers (*) are pretty fundamental C/C++ constructs.
Just about any tutorial should cover the subject.
What is it you're trying to do?
http://www.cplusplus.com/doc/tutorial/
-> http://www.cplusplus.com/doc/tutorial/pointers/
or typing 'c++ pointers' into google returns a whole bunch.
AWOL Asks : What is it you're trying to do?
Well, I got an array
char *dataarray[25];
and I have to use this data in multiple part of my script.
And for one of it, need to use the data to change the mac address of my Arduino.
And I tried :
for (int i = 0 ; i < 6; i++){
mac[i] = byte(dataarray[i]);
}
Moderator edit: CODE TAGS added - italics suppressed
And this failed. Cannot change the type of the dataarray as it is used in other part of code.
that is an array of 25 pointers equivalent to
char **dataarray; //just to confuse you more
are you sure that is correct.
Sure
The first 6 pointers are for mac, the others are for the rest of the code. This array is the result of the parse of a client request.
Thanks for the "just to confuse you more".... I am now more confused....
The first 6 pointers are for mac,
And how is the MAC represented?
Like AWOL asked ( probably haven't had a chance to reply ) And how is the MAC represented?, and myself pointed out in my first post
char* dataarray[25];
is an array of 25 char * <<< 25 addresses.
your mac is most probably char's <<< data
so the 2 byte addresses are not fitting in the mac byte ( unsigned char ) data space.
How Mac represented... not qui te sure to understand the question. Need to replace the original array
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
So, now I've understood the problem I got. Is there any chance for me to 'extract' the data of at a specific addresse ? For me as a beginner, I find strange that if I enter
Serial.println(dataarray*); // (with i=5 for example)*
I got an answer wich is corresponding to the content and not the address... I got so many things to learn...
Then, my question is : how to convert the content and not the address...
pYro, thanks for the links, didn't have time to read these, but I promise you that I will read these carefully.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
You still haven't answered how the MAC that is pointed to by the elements of "dataarray" are represented.
If they're simply bytes, then
for (int i = 0 ; i < 6; i++){
mac[i] = byte(*dataarray[i]);
}
but if they're strings, then you need to convert them to bytes first.
Awol, Pyro, the code has compiled...
Don't know where you are, but would have the opportunity to pay you a beer for your help.
First, you have solved my problem with only adding a * to my code, plus, I had the pleasure to learn lot more today.
This development is really important and will probably save a hudge project in RFID access control.
Then, many thanks from France
the code has compiled...
In which case, your troubles may only just have begun.
(I'll have a Kanterbrau)