Y
Yodai
Hi all....
I got this function I worked on that has to receive a variable and return a
value, but it doesn't seem to work.
It does compile, but it doesn't return a thing..... I am fairly positive
that the error is in Detect_type(). What I do is:
char* Detect_type(volatile char tipus)
{
int i;
char escape[6] = "empty";
struct decide {
unsigned num;
char *string;
}
cadena [] = {
{0x00 , "stv1pk"},
{0x02, "stv1rms"},
{0x04, "itv1rms"},
{0x06, "ian1pk"},
{0x08, "ian1rms"},
{0x0A, "i1pk"},
{0x0C, "i1rms"},
{0x0E, "vccoff"},
{0x10, "vccon"},
{0x12, "rearme"},
{0x14, "magneto"},
{0x16, "offmanual"},
{0x18, "interno"},
{0x1A, "remotein"},
};
for(i = 0; i < sizeof(cadena) / sizeof(cadena[0]); i++)
if(cadena.num == tipus) return cadena.string;
return (escape);
}
//and then from somewhere in my main I call this function to translate
values for me like this:
case 'a' :
{
volatile char tipus = *R1TIPUS ;
sprintf(NewKey, "%u", Detect_type(tipus));
memcpy(Key, NewKey, 10);
break;
}
case 'b' :
{
volatile char tipus = *R2TIPUS ;
sprintf(NewKey, "%u", Detect_type(tipus));
memcpy(Key, NewKey, 10);
break;
}
I got this function I worked on that has to receive a variable and return a
value, but it doesn't seem to work.
It does compile, but it doesn't return a thing..... I am fairly positive
that the error is in Detect_type(). What I do is:
char* Detect_type(volatile char tipus)
{
int i;
char escape[6] = "empty";
struct decide {
unsigned num;
char *string;
}
cadena [] = {
{0x00 , "stv1pk"},
{0x02, "stv1rms"},
{0x04, "itv1rms"},
{0x06, "ian1pk"},
{0x08, "ian1rms"},
{0x0A, "i1pk"},
{0x0C, "i1rms"},
{0x0E, "vccoff"},
{0x10, "vccon"},
{0x12, "rearme"},
{0x14, "magneto"},
{0x16, "offmanual"},
{0x18, "interno"},
{0x1A, "remotein"},
};
for(i = 0; i < sizeof(cadena) / sizeof(cadena[0]); i++)
if(cadena.num == tipus) return cadena.string;
return (escape);
}
//and then from somewhere in my main I call this function to translate
values for me like this:
case 'a' :
{
volatile char tipus = *R1TIPUS ;
sprintf(NewKey, "%u", Detect_type(tipus));
memcpy(Key, NewKey, 10);
break;
}
case 'b' :
{
volatile char tipus = *R2TIPUS ;
sprintf(NewKey, "%u", Detect_type(tipus));
memcpy(Key, NewKey, 10);
break;
}