Hi,
I have some images which I update like below:

count++;
if(count >= sizeOfArray)
{
    count = 0;
}
for(u32 i=0; i<sizeOfArray; i++)
{
    s_image[i].image->setVisible(false);
    s_image[i].reverse->setVisible(false);
}

I want to know, how do I reverse it. I mean, it is increasing the count and I want to decrease it. The sizeOfArray is 4.

Thanks in advance.
Regards.

Just change the loop so that i is initialized to sizeOfArray-1, and loop until i == 0

Could you kindly elaborate a little please. When I reverse the code it decreases but once it excceds 0 the programe crashes and the count shows on output this number -

Count: 4294967295

Regards.

The problem is here:

m--;
if(m <= 0)
{
    m = 4;
}

The output:

M: 4294967295

But it works with m++. Can anyone tell me why it does not work in c++?
Regards.

The problem you are having is that you are using an unsigned integer type. When you underflow that type it wraps around to the largest number it can be. You have to be very careful when you get towards the min or max number that your type can hold because sometimes this will happen. One nice feature of this is that if you want the largest number that an unsigned type can hold you can always subtract one from 0 and you will get the max.

Unsigned int: 0 - 1 = 4294967295

Unsigned int: 4294967295 + 1 = 0

Ya, took me a little time to understand the problem. I realise I did not provide required information in my question. The sizeOfArray should not be = 4. Thats why it was crashing.

Thanks for the input.
Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.