Help with bit vector and setting its bits?

 
void shuffle (card_t cards[], card_t cards2[], char *bitvec)
{
int i;
unsigned char temp, r;
srand(time(NULL));
for (i = 0; i < 52; i++)
{
r = rand() % 52;
temp = bitvec[r/8];
if (!(temp & (1 << (8- (r % 8)))))
{
temp |= (1 << (8- (r % 8)));------->is this my problem?
}
}
}

ok so I am trying to use a bit vector to keep track of some random numbers and I suppose I just dont understand how to use bit operations verry well since i thought that this code would work but from the results i have been getting the bit just stays 0 no matter what. So i want to check and see if the bit is 0 and if it is i want to set it to one but either my check or set of the bit isnt wokring. if anyone would please tell me what im doing wrong i would appreciate it.

There is no problem with your bitwise operations. Your pointers on the other hand ...

Do you expect changing temp to change bitvec? That'd require a pointer. You're not using one. Also, there is no point checking if the bit is unset if you're going to set it. If it's unset and you set it is the same as if it's set and you set it... Make sense?

So throwing out the temp variable (or using pointers) and throwing away the if condition, your code works here:

        for (i = 0; i < 52; i++)
        {
                r = rand() % 52;
                printf("round %d: r=%d bitvec[%d]=%d bit=%d ",
                        i, r, r/8, bitvec[r/8], 8 - (r % 8));
                bitvec[r/8] |= (1 << (8 - (r % 8)));
                printf("bitvec now=%d\n", bitvec[r/8]);
        }