Quote Originally Posted by rahulnair87 View Post
The code u wrote will replace every fourth element in the array with a zero, but i want to INSERT a zero in every fourth index.
which also means that on each insertion u got to shift the array by one.

Now , pls put in your valuable suggestions and the array size is about 1300000.

regards
Rahul
Please use code tags and complete, real words.

Arrays don't really support insertion, so it's going to be time consuming. Can you use a list?

Obviously you're going to have to create a new array with a larger size. I'd look at figuring out how big the new array needs to be then making one allocation with the new size. memset the whole thing to zero, then use memcpy to copy four elements at a time from the old array to the new one skipping every fourth element.

This is completely untested, but may point you in the right direction.

Code:
int newsize = (oldsize * 125) / 100;
char* newArray = new char[newsize];
memset(newArray, 0, newsize);
int nSkip = 0;
for(int i = 0; i < oldsize; i += 4)
{
   memcpy(newArray + i + nSkip, oldArray + i, 4);
    nSkip++;
}