Считываю jpeg в unsigned char*.
FILE* file;
if((file = fopen("1.jpg", "rb+")) == NULL) {
printf("Ошибка открытия файла.\n");
exit(1);
}
fseek (file, 0 , SEEK_END);
int length = ftell(file);
rewind (file);
std::cout << "length: " << length << std::endl;
data = (unsigned char*)malloc(sizeof(unsigned char)*length);
if (data == NULL) {
fputs ("Memory error",stderr);
exit(2);
}
size_t result = fread(data, 1, length, file);
if (result != length) {
fputs ("Reading error",stderr);
exit (3);
}
fclose(file);
std::cout << "strlen(data): " << strlen((char*)data) << std::endl;
std::cout << (char*)data << std::endl;
free(data);
В итоге получаю
length: 106554 // верное значение
strlen(data): 4
����
Чтение проходит корректно, я далее то что хранится в unsigned char записываю в новый файл jpeg и он открывается нормально. Как узнать размер значения хранящегося в unsigned char?