My programme keeps producing a segmentation fault. I have simplified my code to the following:
#include <stdio.h>
void open_file(FILE** file)
{
*file = fopen("test" , "wb");
return;
}
int main ()
{
int Tracks = 1;
FILE* Files;
int i = 1;
Files = new FILE[Tracks + 1];
printf("i = %d\n", i); //i = 1
open_file(&Files + i);
printf("i = %d\n", i); /i = 0
fclose(*(&Files + i)); //Segmentation fault
return 0;
}
I must be doing some really stupid pointer-error, but to me my pointer-arithmetics operations look fine... The problem is, that for some magic reason, the variable i changes its value to 0. Could someone explain to me why??
Thanks in advance!