Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by Simba ( 16 years ago )
#include <stdio.h>
// тип, описывающий байтовый массив
typedef struct bytearray_struct{
char* array;
long size;
} bytearray;
// функция принимает имя файла и выдает его содержимое в виде байтового массива
bytearray* loadFile(char* file_path)
{
FILE* f = fopen(file_path, "rb");
if ( f == NULL )
return NULL;
// узнаем размер
fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, 0, SEEK_SET);
// создаем байтовый массив
bytearray* ba = new bytearray;
ba->array = new char[size];
ba->size = size;
// считываем данные из файла и закрываем его
fread(ba->array, size, 1, f);
fclose(f);
// возвращаем байтовый массив
return ba;
}
// сохраняет байтовый массив в файл
int saveToFile(char* file_path, bytearray* ba)
{
FILE* f = fopen(file_path, "w+");
fwrite(ba->array, ba->size, 1, f);
fclose(f);
}
int main()
{
bytearray* ba = loadFile("/home/anton/Downloads/System Of A Down - Boom.mpeg");
saveToFile("/home/anton/test.mpeg", ba);
delete ba;
}
Revise this Paste
Children: 24775