First of all, change the below otherwise you will never enter your "menu".
op = op_menu(); //op should be assigned by the return value of open_menu
if (op==1){...
if (op==2){... // I believe you want '==' not '='
According the comments you have to invoke read_registry
method. The added code:
if (op==1){
//insert
veiculo_t *t = malloc(sizeof(veiculo_t));
read_registry(t);
FILE *f=fopen("veic.dat", "ab");
if (f == NULL)
{
printf("open file failed\n");
}
fwrite(t, sizeof(char), sizeof(*t), f);
free (t);
}
if (op==2){
//print
FILE *f=fopen("veic.dat", "rb");
if (f == NULL)
{
printf("Not opened!\n");
}
else
{
veiculo_t *t = malloc(sizeof(veiculo_t));
printf("sizeof t: %d\n", sizeof(*t));
while(fread(t, sizeof(char), sizeof(*t), f))
print_registry(t);
free(t);
}
The example code just for you refrence, I would like to provide a thinking more than an answer, but seems code always is clear and powerful. In below example I write file use append mode, if you want re-write file every time, change mode in fopen
when write file.
Hope that helpful.