I want to read a video file and save as binary and write as a video file again. I tested with 180MB video. I used fread function and It occur segmentation fault because array size is small for video.
those are my questions:
I use 160*1024 bytes char array. What is the maximum size of char array? How I can solve this problem?
this program need to work as:
I can't upload my code because of security rule of company. Any tip would be appreciated.
first use fseek()
with SEEK_END
, then use ftell()
to determine the file size, after that allocate the needed memory with malloc()
and write the data to that memory.
If I understand you correctly you don't need to allocate so much memory, but only 128 Bytes.
char buf[128];
while(/* condition */)
{
ret = fread(buf, sizeof buf, 1, fp_in);
encrypt(buf);
ret = fwrite(buf, sizeof buf, 1, fp_out);
}