# Thread: shifting 1D array items down

1. ## shifting 1D array items down

I am trying the following but I think its not getting to the last, item or something, can someone have a look and see if im right for the shifting of the array (red bit):

Code:
```int smallItems=0;
for(listi=0; listi<numOfItems; listi++)
{
for (j=0;j<height;j++)
{
for (i=0;i<width;i++)
{
if(array2[j][i] == objects[listi])
{
smallItems++;
}
}
}
if(smallItems < 525)
{
for (j=0;j<height;j++)
{
for (i=0;i<width;i++)
{
if(array2[j][i] == objects[listi])
array2[j][i] = 0;
}
}
for(i=listi; i<numOfItems-1; i++)
{
objects[listi] = objects[listi+1];
}
listi--;
numOfItems--;

}
printf("SmallItems: %d, listi: %d\n", smallItems, listi);
smallItems = 0;
}```

2. By down do you mean left or right ?

This will shift left and overwrite the first element -

eg:

0 1 2 3
^
1 1 2 3
^
1 2 2 3
^
1 2 3 3
...

What exactly are you wanting to do ?

3. i mean from right to left
so
Code:
```1 2 3 4
^
should become
1 2 4

given 3 is deleted```
Basically objects[] contains an array of variables and in this test case say 4. Then i perform some function to determine if I have to get rid of an item in objects[] in which case i shift items down and take 1 of numOfItems(which contains how many items are in objects[])

For some reason numOfItems at the beginning of the for loop is 4, but then at the end after it its 0 when it should be 1

4. Let's say our array has only: 1 2 3 4
You want to get rid of the 3: 1 2 4 ?
What's going to end up in the last spot? There's nothing that you can put there that will mean "empty" really. You need to sort of figure out what you want to happen to that last spot.

Quzah.