Hello all,
I am trying to append a char to a char* which is returned from a function -- I'll demonstrate this with an example:
Code:
typedef struct
{
char key;
int value;
} charmap_t;
charmap_t t[] =
{
{'s', MaskS},
{'c', MaskC},
{'l', MaskL},
{'m', MaskM},
{'1', Mask1},
{'2', Mask2},
{'3', Mask3},
{0, 0}
};
char *modifier_to_string(int mask, charmap_t *t)
{
char *mods = malloc(20);
char c;
for (c = 0; t->key !=0; t++)
{
if (mask & t->value)
{
c = table->key;
strcat(mods, (char *)&c);
}
}
return allmods;
}
This piece of code works OK -- although when trying to print the result returned from the function above I get garbage, as in:
Code:
char *mod_string = modifier_to_string(2, modifiers);
fprintf(stderr, "Modifier:\t%s\n", mod_string;
I know that "2" exists, and that modifiers (of type charmap_t) is being iterated over, but still I get garbage.
Any ideas?
Thanks!