Shrinking/trimming an array?
I'm trying to cut data from the beginning and end of an array, but my idea isn't working. The first memcpy line compiles but crashes the program. I can't figure out the right way to do it. This array pointer crap always confused me. It should be possible to memcpy from a location in the array though. Any ideas?
Code:
unsigned char *tmpResults;
if (!(tmpResults = (unsigned char*)malloc((RamInfo.ResHigh - RamInfo.ResLow)/Search.Size/8 ))) {
sprintf(ErrTxt, "Unable to allocate shrink results memory () -- Error %u", GetLastError());
MessageBox(NULL, ErrTxt, "Error", MB_OK);
goto RUN_SEARCH_ERROR;
}
memcpy(&tmpResults, &RamInfo.Results[RamInfo.ResLow >> 3], (RamInfo.ResHigh - RamInfo.ResLow)/Search.Size/8);
free(RamInfo.Results); RamInfo.Results = NULL;
if (!(RamInfo.Results = (unsigned char*)malloc((RamInfo.ResHigh - RamInfo.ResLow)/Search.Size/8))) {
sprintf(ErrTxt, "Unable to allocate results memory (DO_SEARCH_CMD) -- Error %u", GetLastError());
MessageBox(NULL, ErrTxt, "Error", MB_OK); goto RUN_SEARCH_END;
}
memcpy(&RamInfo.Results, &tmpResults, (RamInfo.ResHigh - RamInfo.ResLow)/Search.Size/8);
free(tmpResults);