I am trying to construct an array that has a series of character that I want to construct in the fly, the characters are like this \x01
, \x02
and so on.
For example, lets say we have:
#define NUMCOLORS 3
char delim[NUMCOLORS];
And we want to have in delim
the values \x01, \x02, \x03
.
I thought two possible ways to do it, but both cause a segfault:
for (int i = 0; i < NUMCOLORS; i++){
char *h = "\x01";
sprintf(h, "\x0%d", i+1);
strcpy(delim[i], h);
}
// Other way
for (int i = 0; i < NUMCOLORS; i++){
char *h = "\x0";
strcpy(delim[i], h+1);
}
Is there a way I can create the char
I need