[C con Clase] ERROR CUANDO BUSCO POR UN REGISTRO

Miguel Angulo Martínez djfunk19 en hotmail.com
Mie Abr 4 16:15:45 CEST 2012


Hola estoy buscando un campo por un registro que es I01 y lo he pasado a cadena  y me sacan tambien los campos I011 e I010

Aqui esta el codigo. que estoy haciendo mal?

void consultas_ID(void)
{
    canal_habitacion=fopen(FICHERO_HABITACION,"rb");  // Si el archivo no existe informa del error e interrumple el programa

    if(canal_habitacion==NULL)
    {
        printf("\n\nERROR\t El archivo 'HABITACIOIN.DAT' no existe o no se puede acceder a el.");
        getch();
        exit(0);
    }
    fclose(canal_habitacion);
    canal_habitacion=fopen(FICHERO_HABITACION,"r+b");  //Abre el archivo en modo lectura-escritura binaria
    fseek(canal_habitacion,0L,0); //Me situlo al princio;
    fread(&registrohab, sizeof(registrohab),1,canal_habitacion); //Leo el archivo con el molde "indice"
    N=registrohab.num_registro;

    if(N==0){
    //Si el archivo esta vacio informa del error e interrumpe el programa
    printf("\nERROR\tEL archivo 'HABITACION.DAT' esta vacio");
    getch();
    exit(0);
    }
    do{
            clrscr();
            printf("\nIntroduzca el ID_HABITACION del contacto que desea visualizar => ");
            fflush(stdin);
            gets(buscarID);  //Lee el nombre introducido por el usuario

            sw=0;

            for(int i=1; i<=N; i++)  //Bucle que recorre el archivo
            {
                desplazamiento = i*sizeof(habit);  //saltando de 32 en  32 bytes.
                fseek(canal_habitacion,desplazamiento,0);  //me situo
                fread(&habit, sizeof(habit),1,canal_habitacion);
                if(strncmp(habit.id_habitacion, buscarID, strlen(buscarID))==0)
                {
                    if(habit.id_habitacion[0]=='I')
                    {
                        printf("\n*******************************************\n");
                        printf("\n\t TIPO HABITACION : INDIVIDUAL ");
                        printf("\n\t ID HABITACION %s",habit.hindividual.id_habitacion);
                        printf("\n\t Precio %3.2f",habit.hindividual.precio);
                        printf("\n\t Estado: %s",habit.hindividual.estado);
                        printf("\n\t Nº HABITACIONES: %d",habit.hindividual.NUM_INDI);
                        printf("\n*******************************************\n\n");
                        getch();
                    }
                    if(habit.id_habitacion[0]=='D')
                    {
                        printf("\n*******************************************\n");
                        printf("\n\t TIPO HABITACION : DOBLE ");
                        printf("\n\t ID HABITACION %s",habit.hbdoble.id_habitacion);
                        printf("\n\t Precio %3.2f",habit.hbdoble.precio);
                        printf("\n\t Estado: %s",habit.hbdoble.esta);
                        printf("\n\t Nº HABITACIONES: %d",habit.hbdoble.NUM_DBL);
                        printf("\n*******************************************\n\n");
                        getch();

                    }

                    sw=1;
                }
            }
            if(!sw)
            {
                printf("\n\aERROR\tLa entrada %s no se encuentra en el fichero:");
            }
            printf("\n\n\t¿Quieres consultar otro contacto (s/n)? =>");
            fflush(stdin);
    }while(getchar()=='s');

    fclose(canal_habitacion);

}

 		 	   		  
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20120404/86c50c2d/attachment.html>


Más información sobre la lista de distribución Cconclase