I have a problem with this function, I would need the id to auto-add each time I want to create a user, the function works, the problem is that when the program is closed and reopened the counter returns to 0 and does not at the value I had before, some help? Thanks.
#define maxchar 30
typedef struct{
int id;
char usuario[maxchar];
char nombre[maxchar];
char apellido[maxchar];
char domicilio[maxchar];
char localidad[maxchar];
int eliminado; // indica 1 o 0 si el cliente fue eliminado
}Cliente;
void reg_usuario ()
{
int cont=0;
char control = 's';
FILE* fichero ;
Cliente cl; // creo un nuevo cliente de la estructura cliente
fichero=fopen("datos_usuarios","a+b");
if(fichero==NULL)
{
fichero=fopen("datos_usuarios","a+b");
}
if(fichero!=NULL)
{
printf ("Menu de Ingreso de usuarios\n");
while(cont<30 && control == 's')
{
printf ("generando ID de usuario automaticamente...\n");
fflush(stdin);
idaux++;
cl.id = idaux;
printf("\nIngrese su usuario: ");
gets(cl.usuario);
printf ("\n Ingrese Nombre: ");
fflush(stdin);
gets(cl.nombre);
printf ("\n Ingrese Apellido: ");
fflush(stdin);
gets (cl.apellido);
printf ("\n Ingrese Domicilio: ");
fflush(stdin);
gets (cl.domicilio);
printf ("\n Ingrese Localidad:");
fflush(stdin);
gets (cl.localidad);
fwrite (&cl, sizeof (cl), 1, fichero);
printf ("desea cargar otro usuario? (s/n)");
fflush(stdin);
scanf("%c",&control);
cont ++;
}
fclose(fichero);
}
}