I did a proyect which writes and reads to a binary file, but in each function I opened and closed the file, so I tryed to pass the file pointer to the functions so i would only have to open it once, however the program compiles but doesnt run, it says "the program stopped working", here's a part of the code:
Im new to programming, it would be pretty cool if someone showed me what the problem is...
PD: the double pointer is an random idea to try to fix the problem, it helped to make it compile but doesnt work...
thanks
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#define ARCHIVO "data.bin"
#define SIZE sizeof(person)
typedef struct
{int i_id;
char name[20];
int active;} person;
void v_menu(FILE *f);
void v_list(FILE **f, person someone);
int main()
{
FILE *f;
fopen(ARCHIVO,"wb+");
v_menu(f);
return 0;
}
void v_menu(FILE *f)
{
int i_option;
person someone;
do{
system("cls");
printf("\n\n\t\t1. Add.\n\t\t2. Modify.\n\t\t3. delete.\n\t\t4. Consult.\n\t\t5. List.\n\t\t6. Fin.\n\n\t\t\t\t");
scanf("%d",&i_option);
system("cls");
switch(i_option)
{
// case 1:{v_agregarRegistro(&f, registro);break;}
// case 2:{v_modificarRegistro(&f, registro);break;}
// case 3:{v_eliminarRegistro(&f, registro);break;}
// case 4:{v_consultarRegistro(&f, registro);break;}
case 5:{v_list(&f, someone);break;}
}
}
while(i_option!=6);
}
void v_list(FILE **f, person someone)
{
fseek(*f,0,SEEK_SET);
while(fread(&someone,SIZE,1,*f))
{
if(someone.active==1)
printf("\n\n\t\tID: %d\n\t\tName: %s",someone.i_id,someone.name);
}
getch();
}