I am struggling to find a way to write the alphabet letters in a char* using for. If I only had to do that using a table of chars, it'd be like this
for(i=0;i<26;i++) {
character[i] = 'a' + i;
}
But I have a function that requests a char *, so I have to use "something"
instead of 'something'
. Can you help me?
Thank you!
EDIT
Sorry I wasn't clear before. It seems I am quite tired.
The XPM structure is at it follows:
struct XPM {
unsigned int width;
unsigned int height;
unsigned char cpp;
unsigned int ncolors;
Color *colta;
unsigned int *data[];
};
So, the function I have to use is the following:
void setXPMColor(XPM *imagine,
unsigned int index,
unsigned char r,
unsigned char g,
unsigned char b,
char *charpattern) {
imagine -> colta [ index ].r = r;
imagine -> colta [ index ].g = g;
imagine -> colta [ index ].b = b;
imagine -> colta [ index ].pchars = charpattern;
}
In the main() function, I have the following line of code:
for( i = 0; i < NCOLORS; i++ ) {
setXPMColor( image, i, 5 * i, 0, 0, SOMETHING);
}
What can I put insead of SOMETHING in the function, so for every index, I'll have a different character? (I was thinking of putting a new letter or any kind of symbol for each entry). Later I will have to use the symbols to generate an image.
So, in the end I would want something like:
printf("%s\n", imagine->colta[0].pchars); //a
printf("%s\n", imagine->colta[1].pchars); //b
printf("%s\n", imagine->colta[3].pchars); //c
//etc
EDIT 2:
I will have to generate an XPM file that will create an image, so I will have to draw the characters in the file. The problem is giving the function setXPMColor
the character because it needs a char* if I send it for e.g. 'a'
it will say type mismatch, the function requires a char* but it receives an int. It works only if I send it the letter in block quotes like "a"
, but then I cannot increment the letter on each iteration. I hope it helps!
Thank you!