I am writing an algorithm in C which takes pointer to an array of unsigned integers as input does some sort of filtering and returns the results back to the same the pointer array. I did this:
static void Filtering(Inst_t *psStruct, uint8 *arraypointer)
{
uint8 *arrayFilter;
uint32 i, n = 0, uCount;
uCount = psStruct->uCount;
for (i = 0; i < uCount; i++)
{
arraypointer[i] = (arraypointer[i] + arraypointer[i - 1] + arraypointer[i + 1])/3;
}
}
Doing so overwrites the data. But I dont want that to happen. So want to make a local copy of the array data the pointer is pointing to and then use that to compute the average and pass the computed value back.
I am thinking of allocating an array of the size of *arraypointer and initiliazing it with the pointer array values and use this local copy instead. theoritically, this makes sense to me but not sure if this is the best way to do it.
Any pointers/ code to address this problem is highly appreciated. Please help.
Thanks in advance.