Firstly, I'm french and I don't speak and write very well english langage. So sorry for the faults of langage.
Recently, i'm in intership in a company and, I'm stopped in this problem that I will expose you.
I have to copy a binary file in another binary file, in suppress the 8 first octets of my source file. And I'm not allowed to use dynamic variable, Ihave to use POINTER.
And my big problem is that, I have some difficulties to use pointer, and when I use the function "fwrite" to copy informations source file to the Target File, I have an error message: "out-of bounds pointer artmetic:5bytes(5elements) past end of array"
So if someone can telle me what I might forget or suppresss in my program.
It doesn't work, because, we need the function "fseek" before "ftell", and before "fseek", we need "fread", and buffer initalization can't be put after this program lines:
fread(Buffer,1,sizeof(Buffer),FileBin);
if (fseek(FileBin,0,SEEK_END) != 0)
{
fclose(FileBin);
}
It doesn't work, because,
we need the function "fseek" before "ftell",
Agreed
and before "fseek", we need "fread",
But how do we know how many bytes to read?
and buffer initalization can't be put after this program lines:
I agree it cannot go after fread.
The way I see things it goes like this:
1. open files
2. seek to end of input
3. get the position which gives the size of the file
4. allocate buffer with size = file size
5. seek to start ( rewind )
6. read entire file into buffer
7. write from buffer with offset=8 to output file
8. close both input and output files and free the buffer