我正在读取缓冲区(char *)并且我有一个光标,我在其中跟踪缓冲区的起始位置,有没有办法将字符 7-64 复制出缓冲区,或者我最好的选择只是循环从位置 x 到位置 y 的缓冲区?
目标缓冲区的大小是另一个函数动态计算的结果
初始化这个返回
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;
}