FIFO queue for a 2D array in ANSI C I have a 2D array of fixed size and I've implemented a FIFO function. So, the array will always be full before it reaches the FIFO function, then the FIFO will remove the oldest array, move all of the arrays up by one and then add the newest array to the other end. Basically a queue. Now, this code will actually be running on a microcontroller, an array will come from an ADC and then I store the ADC array in a 2D array. To design the FIFO algorithm in simple C first, I have written a program that generates random numbers and then stores them into a 2D buffer. The program then asks the user what new values should be stored, user puts in the latest array of values and then the program removes the oldest array, shuffles all the remaining arrays up by one and then the latest user numbers get added to the end. The program does this 10 times. This is designed to simulate what is happening in the microcontroller code. The 2D array is already full with values and then the ADC adds the latest set of values to the array, and the oldest set are forgotten.
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
int fixed_number[5] = { 0 };
uint16_t big_array[10][5] = { 0 };
uint16_t big_array_copy[10][5] = { 0 };
uint16_t small_array_1[5] = { 0 };
uint16_t k[1] = { 0 };
uint8_t count = 0;
int main()
{
    for (int j = 0; j &lt; 10; j++)
    {
        for (int i = 0; i &lt; 5; i++)
        {
            big_array[j][i] = rand() % 255;
        }
    }
    for (int j = 0; j &lt; 10; j++)
    {
        for (int i = 0; i &lt; 5; i++)
        {
            big_array_copy[j][i] = big_array[j][i];
        }
    }
    printf(&quot;These are the original numbers in the big array:\n&quot;);
    for (int j = 0; j &lt; 10; j++)
    {
        for (int i = 0; i &lt; 5; i++)
        {
            k[0] = big_array[j][i];
            printf(&quot;%d,&quot;, k[0]);
                    }
        printf(&quot;\n&quot;);
            }
    while (count &lt; 10)
    {
        printf(&quot;Please enter values for queue:\n&quot;);
        for (int i = 0; i &lt; 5; i++)
        {
            scanf_s(&quot;%d&quot;, &amp;fixed_number[i]);
        }
           printf(&quot;\n\n&quot;);
        printf(&quot;Array values have been swapped:\n &quot;);
        for (int k = 0; k &lt; 5; k++)
        {
            big_array_copy[10 - 1][k] = 0;
        }
                for (int j = 9; j &gt; 0; j--)
        {

            for (int i = 0; i &lt; 5; i++)
            {
                //small_array_1[i] = big_array[j + 1][i];
                big_array_copy[j][i] = big_array[j - 1][i];
            }
        }
        for (int i = 0; i &lt; 5; i++)
        {
            big_array_copy[0][i] = fixed_number[i];
        }
        for (int j = 0; j &lt; 10; j++)
        {
            for (int i = 0; i &lt; 5; i++)
            {
                k[0] = big_array_copy[j][i];
                printf(&quot;%d,&quot;, k[0]);
            }
            printf(&quot;\n&quot;);
        }
        for (int j = 0; j &lt; 10; j++)
        {
            for (int i = 0; i &lt; 5; i++)
            {
                big_array[j][i] = big_array_copy[j][i];
            }
        }
        count++;
    }
}

Now this code works perfectly fine, but there is a lot of loops and it also requires twice the memory space as the buffer, big_array[][] must be copied in to big_array_copy[][]. In the real application, the buffer is uint16_t somebuffer[100][45] which is 4.5kb. I've got 512kb of SRAM to use, but I'd rather use as little as I can.
The above method can be implemented on my target platform (STM32F767 for those wondering) but is there a more simple method to implementing the above, that uses fairly portable c with no special functions, that could reduce the memory required and the processing time required?
thanks
We're missing an include of &lt;stdint.h&gt;.  On the other hand, we include  &lt;time.h&gt; which we're not using.
The code doesn't compile here because of the use of Annex K scanf_s() without checking for its availability.  There's no reason not to use ordinary scanf() here (but do examine its return value - that's important!)
There are a lot of magic constants sprinkled throughout the code, with no indication whether they relate to each other.  That makes this an unmaintainable program, because you can't change any of those individually without understanding the whole program.
Also, with all the functionality thrown together in main(), that makes it harder to understand the purpose of each part of the code.  Please divide the code into well-named functions (probably with static linkage).
I recommend fixing those before posting another review request to look at this in any depth.