D
decoy
Hi,
I'm having a little trouble with structs, can someone please help?
I have the following:
struct Card
{
Image* image;
int value;
};
struct Card* cards[52];
and assign it here:
int count = 0;
int a = 0;
int total = 0;
char* letter[] = {"c","d","h","s"};
char filename[10];
while(a < 13)
{
sprintf(filename, "%s%d.png", letter[count], a);
struct Card c;
c.image = loadImage(filename);
if(!c.image)
{
printf("failed to load: %s", filename);
}
c.value = a == 0 ? 0 : (a + 1 > 10 ? 10 : a+1);
cards[total++] = &c;
if(a == 12)
{
count++;
if(count ==4) a = 1000000;
else a =0;
}
else
{
a++;
}
}
My problem is that when I go through the array I only seem to get the
values for the last Card object that I added:
int b = 0;
while(b < 52)
{
struct Card* cg = cards;
printf("%d) value: %d\n", b++, (*cg).value);
blitAlphaImageToScreen(0 ,0 ,72 , 96, (*cg).image, 210,100);
}
Many thanks in advance for your help.
I'm having a little trouble with structs, can someone please help?
I have the following:
struct Card
{
Image* image;
int value;
};
struct Card* cards[52];
and assign it here:
int count = 0;
int a = 0;
int total = 0;
char* letter[] = {"c","d","h","s"};
char filename[10];
while(a < 13)
{
sprintf(filename, "%s%d.png", letter[count], a);
struct Card c;
c.image = loadImage(filename);
if(!c.image)
{
printf("failed to load: %s", filename);
}
c.value = a == 0 ? 0 : (a + 1 > 10 ? 10 : a+1);
cards[total++] = &c;
if(a == 12)
{
count++;
if(count ==4) a = 1000000;
else a =0;
}
else
{
a++;
}
}
My problem is that when I go through the array I only seem to get the
values for the last Card object that I added:
int b = 0;
while(b < 52)
{
struct Card* cg = cards;
printf("%d) value: %d\n", b++, (*cg).value);
blitAlphaImageToScreen(0 ,0 ,72 , 96, (*cg).image, 210,100);
}
Many thanks in advance for your help.