Q:

keeping same array size while adding values

I am trying to think of way to keep a history of commands in an array of size [10], and while keeping its size constant, to always show the last 10 commands. Is there an implementation that does not involve Queues or Lists? Maybe something like, giving the array some more space, and filling the commands, but printing different index? I am using C on Windows machine.

A:

Just treat your array like a circular buffer and keep an cur variable pointing at the most recent entry.

To add an entry:
cur = (cur + 1) % size;

To print everything in the array:
printf("%d\n", cur);
for (i = (cur + 1) % size; i != cur; i = (i + 1) % size)
    printf("%d\n", i);

