Solved! Go to Solution.
val.a[] = "AE";
I think you meant here
strcpy(val.a, "AE");
or
memcpy(val.a, "AE", 2);
Thank you!
It is very easy
And how can I convert a counter (stored in an unsigned char) to a string?
I mean:
0xFF >> 255 >> 32:35:35 (ASCII values)
Sorry about that. I was somewhat confused with the initialisation process allowed within the definition of an array variable.
Another alternative to the use of the copy functions might be to load each of the two array elements separately -
val.a[0] = 'A';
val.a[1] = 'E';
or perhaps create a function -
unsigned short getval( char *s)
{
ascseq temp;
temp.a[0] = s[0];
temp.a[1] = s[1];
return temp.b;
}
with the following usage -
unsigned short i;
i = getval( "AE" );
Regards,
Mac
Hello,
Assuming big endian data format, simply create a union between a char array and an unsigned short variable.
typedef union {
char a[3]; // Allow for null termination
unsigned short b;
} ascseq;
ascseq val; // Define variable
To load data to the array -
val.a[] = "AE";
To read the equivalent integer value, use val.b
Regards,
Mac
val.a[] = "AE";
I think you meant here
strcpy(val.a, "AE");
or
memcpy(val.a, "AE", 2);