我正在通過緩衝區(char *)進行讀取,並且我有一個光標,在那裏我正在跟蹤緩衝區的起始位置,有沒有辦法將字符7-64從緩衝區中複製出來,或者是我最好的選擇只是將poistion x中的緩衝區循環到位置y?如何在char *緩衝區中從位置y讀取x個字符?
目標緩衝區的大小是另一個函數的結果動態計算
初始化此返回
variable-sized object 'version' may not be initialized
相關代碼部分:
int32_t size = this->getObjectSizeForMarker(cursor, length, buffer);
cursor = cursor + 8; //advance cursor past marker and size
char version[size] = this->getObjectForSizeAndCursor(size, cursor, buffer);
-
char* FileReader::getObjectForSizeAndCursor(int32_t size, int cursor, char *buffer) {
char destination[size];
memcpy(destination, buffer + cursor, size);
}
-
int32_t FileReader::getObjectSizeForMarker(int cursor, int eof, char * buffer) {
//skip the marker and read next 4 byes
cursor = cursor + 4; //skip marker and read 4
unsigned char *ptr = (unsigned char *)buffer + cursor;
int32_t objSize = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
return objSize;
}
你是對的nhahtdh這不是我的。 –