I'm having problems with const char array being stored to a struct, then when calling the value from a struct I don't always get the expected value.
Below is the code:
typedef struct
{
char *update_type;
char *transaction;
} TickType;
In a thread I have:
const char tx_types[] = "INV/ADD/MOD/DEL/RPL";
const char upd_types[] = "INS/OVR/MOV/DEL";
tick->transaction = &tx_types[4*upd.xpbu_transaction_type];
tick->update_type = &upd_types[4*upd.xpbu_update_type];
This upd.xpbu_transaction_type and this upd.xpbu_update_type return ints (0-4) and (0-3) respectively. In another thread we have printing to file:
fprintf(out, "%3.3s/%3.3s:\n",tick->transaction, tick->update_type);
fflush(out);
The problem is when checking out the output file I see the following:
+MOD/DEL:
+ / Â +:
+MOD/DEL:
+MOD/ :
/@Ea:
/<90>Ea:
/Ã Ea:
/0Fa:
/ :
So as you can see it is only right sometimes.
I'm sure my mistake is in the struct assignment. Unfortunately I can not offer a better look into the code due to it being proprietary software.