Trying to create animation using array function to continuously print out a grid of ints and move each element across 1 place

  animation, arrays, c++

I’m trying to create the effect of 1 traversing down a line of 0’s.

My code is simple loop of "last element placed in holder -> all elements = location – 1
-> cout".

When I run it, I don’t get my int assigned to 1 showing up on the grid.

Can someone tell me where I’ve mis-coded?

int main()
{
    int arr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; // Array values declared
    int* arrPtr[10] = {&arr[0], &arr[1], &arr[2], &arr[3], &arr[4], &arr[5], &arr[6], &arr[7], &arr[8], &arr[9]}; // Point array assigned to array elements

    int holder = 1; // Holds last number in sequence
    int* holderPtr = &holder; // Holder pointer

    while (1) {
        for (int y = 0; y < 10; y++) {
            for (int i = 0; i < 10; i++) {
                cout << *arrPtr[i] << " ";
            }
            cout << endl;
        }                               // Prints out array 10x to create grid

        holderPtr = arrPtr[9];          // Value of last element in array stored in holder pointer
        for (int m = 9; m >= 1; m--) {
            arrPtr[m] = &arr[m - 1];    // Assigns each pointers value to be equal to previous pointer in array
        }
        arrPtr[0] = holderPtr;          // First element in pointer array assigned value stored in holder pointer

        system("CLS");                  // Resets grid
    }

    return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT