R
Richard Bos
Yodai said:Hummm... I have just realized there's an error, so I correct myself: (still
doesn't work, though) the 2nd column should be as "stv1pk" to be a character
string:
void Detect_type(void)
{
volatile char r1tipus = *R1TIPUS;
May I ask why this char is volatile?
unsigned char cadena [14] [2] = {
0x00 , "stv1pk",
0x02, "stv1rms",
Your first item in each row is a char; the second is a pointer to char
(which points to the string literal in question). Arrays do not work
that way. Arrays are meant for a collection of data of the same type.
What you're looking for is a struct. Structs were created to hold data
of different types. For example, you could declare a
struct entry {
char index;
char *data;
};
and then you could have
struct entry cadena[14] = { ... };
Note, BTW, that it is unwise to have several instances of this magic
number 14 in your code. Sooner or later, you'll need to change it, and
then you might forget one. Use a #defined constant, or make this
definition
struct entry cadena[] = { ... };
(which will ask your compiler to figure out the size of the array
itself; this only works with initialised arrays, of course), and then
later on use (sizeof cadena/sizeof *cadena) instead of the magic 14.
int t;
char *v;
for (t=0; t <14; t++) cadena[t] = t;
This obviously does not work, since cadena[t] is a char[2], while t is
an int.
Besides, if all indices are equal to their position in the array, why do
you need the index at all?
if (cadena[t] == r1tipus *v =cadena[2])
Neither does this, for much the same reasons. Look up how arrays and
structs work _exactly_ in your C textbook; you can't just throw in a
random index wherever you like.
Richard