There is a problem in this code. I don't know what to do. If you try to compile it, says:

transformaclave[const *char] cannot be distinguished from tranformaclave[ const char* const]

can anybody help me???
thanks anyway.

//////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                              //
//                                      UNIVERSIDAD DE PALERMO                                         //
//                                                                                              //
//                             TRABAJO PRACTICO DE ESTRUCTURA DE DATOS                          //
//                                       SISTEMA INMOBILIARIO                                   //
//                                          1ER CUAT. 2007                                      //
//                                                                                              //
//                                                                                              //
//                                      xxxxxx, JUAN CARLOS                                    //
//                                                                                                                               //
//////////////////////////////////////////////////////////////////////////////////////////////////


//Programa que permite dar de alta y baja cuentas USUARIO y ADMINISTRADOR del sistema inmobiliario
//Este programa no forma parte del sistema en si, sino que es una aplicacion externa.


//LIBRERIAS***************************************************************************************

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//************************************************************************************************


//ESTRUCTURAS*************************************************************************************

FILE *fh = NULL;

typedef struct
    {
    char tipo_cta[ 1];  //El tipo cuenta puede ser: Administrador o Usuario
                              //Si es tipo Adminstrador se ingresa A
                              //Si es tipo Usuario      se ingresa U
    char nomb[ 12]; //El nombre de la cuenta debe ser de hasta 12 caracteres
    char pass[ 8];  //El password de la cuenta debe ocupar hasta 8 caracteres
    }clave;
//************************************************************************************************


//CONSTANTES**************************************************************************************

const char fich[ 12] = "passfile.dat";
//************************************************************************************************


//DEFINES*****************************************************************************************

#define principal 199                 //Se define la cantidad maxima de cuentas que pueden existir
#define total 240
//#define desplazamiento( n) ( ( n)) * sizeof( clave))
//************************************************************************************************


//PROTOTIPOS**************************************************************************************

void creacion( void);
void alta( void);
void baja( void);
void consulta( void);
void colisiones( clave cla);
int  indexsinonimo( const char c[ ]);
int  hash( char c[ ]);
long transformaclave( const char c[ ]);
void escribir( clave cla);
long desplazamiento( long n);
//************************************************************************************************


//FUNCION MAIN************************************************************************************

void main( )
    {
    char opcion;

    fh = fopen( fich, "rb");              //Comprueba si el archivo ya ha sido creado
    if( fh == NULL)
        {
        puts( "El archivo va a ser creado");
        creacion( ); //Funcion que crea el archivo que va a contener las claves de acceso al sistema
        }
    else
        fh = NULL;

    do
        {
        puts( "1. ALTA        ");
        puts( "2. BAJA        ");
        puts( "3. CONSULTA");
        puts( "");
        puts( "4. SALIR   ");

        do
            {
            printf( "Elige una opcion ");
            scanf( "%c%*c", &opcion);
            } while( opcion < '1' || opcion > '5' || opcion == '4');

        switch( opcion)
            {
            case '1':
                alta( ); break;
            case '2':
                baja( ); break;
            case '3':
                consulta( ); break;
            } //fin_switch

        }while( opcion != '5');
        if( fh != NULL)
            fclose( fh);  //Se cierra el archivo
    } //fin_main
//************************************************************************************************


//FUNCION DESPLAZAMIENTO**************************************************************************

long desplazamiento( long n)
    {
    long res;
    res = n *( sizeof( clave));
    return res;
    } //fin_desplazamiento
//************************************************************************************************


//FUNCION CREACION********************************************************************************
//Esta funcion escribe consecutivamente el total de registros, todos con el campo nomb igual a
//'*' para indicar que estan libres.

void creacion( void)
    {
    clave cla;
    int i;

    fh = fopen( fich, "wb+");
    strcpy( cla.nomb, "*");
    for( i = 1; i <= total; i++)
        fwrite( &cla, sizeof( cla), 1, fh);
    fclose( fh);
    } //fin_creacion
//************************************************************************************************


//FUNCION ALTA************************************************************************************
//Esta funcion da de alta un registro: pide al usuario los campos tipo_cta, nomb, nomb.
//Llama a la funcion hash( ) para obtener la posicion en la que leer el registro, si esta libre
//graba el nuevo registro. Si esta ocupado ocupado, busca en el area de colisiones la primera
//posicion libre que sera donde escribe el registro.

void alta( void)
    {
    clave cla, claar;
    long posicion;

    if( fh == NULL)
        fh = fopen( fich, "rb+");     //Abre el archivo para poder agregar una cuenta

    printf( "Tipo de cuenta   : ");
    gets( cla.tipo_cta);             //Se ingresa el tipo de cuenta
                                                //(A: Administrador, U: Usuario)

    printf( "Nombre de usuario: ");
    gets( cla.nomb);                 //Hasta 12 caracteres
    printf( "Ingresa password : ");
    gets( cla.pass);                 //Palabra clave de acceso

    posicion = hash( cla.nomb);
    posicion = desplazamiento( posicion);

    fseek( fh, posicion, SEEK_SET);
    fread( &claar, sizeof( clave), 1, fh);

    if( strcmp( claar.nomb, "*") == 0)
        {                                              //Si se da el caso de estar el registro libre
        fseek( fh, -sizeof( clave), SEEK_CUR);
        fwrite( &cla, sizeof( clave), 1, fh);
        printf( "La cuenta de acceso se ha guardado en la direccion: %ld\n", posicion);
        }
    else if( strcmp( cla.nomb, claar.nomb) == 0)  //La cuenta ya existe!
        {
        puts( "El nombre de usuario ingresado ya existe.");
        return;
        }
    else
        colisiones( cla);
        fflush( fh);
    } //fin_alta
//************************************************************************************************


//FUNCION BAJA************************************************************************************
//Esta funcion da de baja un registro ( cuenta de usuario): Se pide el nomb ( nombre de
//usuario). Se lee el registro cuya posicion esta determinada por la funcion hash( ). Si los nomb_
//usu (el ingresado y el leido) coinciden, se lo da de baja la cuenta escribiendo '*' en el campo
//nomb. En caso contrario se busca en el area de colisones y se procede igual. Si no se
//encuentra, se da aviso al usuario que el nombre de usuario no existe.

void baja( )
    {
    clave claar;
    char nomb[ 12], r;
    long posicion;

    if( fh == NULL) fh = fopen( fich, "rb+");

    printf( "Nombre de usuario: "); gets( nomb);
    posicion = hash( nomb);
    posicion = desplazamiento( posicion);

    fseek( fh, posicion, SEEK_SET);
    fread( &claar, sizeof( clave), 1, fh);

    if( strcmp( claar.nomb, nomb) != 0)
        posicion = indexsinonimo( nomb);

    if( posicion != -1)
        {
        escribir( claar);
        printf( "¿Son correctos los datos? (S/N): ");
        scanf( "%c%*c", &r);
        if( toupper( r) == 'S')
            {
            strcpy( claar.nomb, "*");
            fseek( fh, -sizeof( clave), SEEK_CUR);
            fwrite( &claar, sizeof( clave), 1, fh);
            }
        }
    else
        puts( "No se encuentra una cuenta con ese nombre de usuario.");
        fflush( fh);
    }//fin_baja
//************************************************************************************************


//FUNCION CONSULTA********************************************************************************
//Esta funcion permite consultar sobre una determinada cuenta. Es util cuando se da el caso de que
//un usuario del sistema( sea del tipo usuario o administrador) se olvida su contraseña. En ese
//caso puede acudir a esta funcion para poder recuperarla.
//Se lee el registro ( o cuenta) cuya posicion esta determinada por la funcion hash( ). Si los
//codigos son iguales se muestra por pantalla. En caso contrario se busca en el area de colisiones.

void consulta( )
    {
    clave cla;
    char nomb[ 12];
    long posicion;

    if( fh == NULL) fh = fopen( fich, "rb+");

    printf( "Nombre de usuario : "); gets( nomb);
    posicion = hash( nomb);
    posicion = desplazamiento( posicion);

    fseek( fh, posicion, SEEK_SET);
    fread( &cla, sizeof( clave), 1, fh);

    if( strcmp( cla. nomb, nomb) == 0)
        escribir( cla);
    else
        {
        int posicion;

        posicion = indexsinonimo( nomb);
        if( posicion != -1)
            {
            fseek( fh, -sizeof( clave), SEEK_CUR);
            fread( &cla, sizeof( clave), 1, fh);
            escribir( cla);
            }
        else
            puts( "No se encuentra una cuenta con ese nombre de usuario.");
        }
    } //fin_consulta
//************************************************************************************************


//FUNCION COLISIONES******************************************************************************
//Inserta en area de sinonimos: busca secuencialmente el primer registro libre( codigo=='*') para
//grabar la cuenta cla

void colisiones( clave cla)
    {
    clave claar;
    int pos = desplazamiento( principal);
    int j = principal;
    int encontrado;

    fseek( fh, pos, SEEK_SET);               //Se situa en el area de sinonimos
    encontrado = 0;

    while( ( j < total) && !encontrado)
        {
        fread( &claar, sizeof( clave), 1, fh);
        j++;
        if( strcmp( claar.nomb, "*") == 0)     //Esta libre
            {
            encontrado = 1;
            fseek( fh, -sizeof( clave), SEEK_CUR);
            fwrite( &cla, sizeof( clave), 1, fh);
            puts( "Cuenta guardada en el area de sinonimos.");
            }
        }
    } //fin_colisiones
//************************************************************************************************


//FUNCION INDEXSINONIMO***************************************************************************
int indexsinonimo( const char c[ ])
    {
    clave claar;
    int pos = desplazamiento( principal);
    int j = principal;
    int encontrado;

    fseek( fh, pos, SEEK_SET);       //Se situa en el area de sinonimos
    encontrado = 0;

    while( ( j < total) && !encontrado)
        {
        fread( &claar, sizeof( clave), 1, fh);
        j++;
        if( strcmp( claar.nomb, c) == 0)
            encontrado = 1;
        }
        if( !encontrado) j = 1;
            return j;
    } //fin_indexsinonimo
//************************************************************************************************


//FUNCION HASH************************************************************************************
//Aritmetica modular: Transforma cadena a un entero en el rango [0, principal). En primer lugar
//pasa los caracteres del codigo a mayusculas. A continuacion, llama a la funcion que convierte
//la cadena a entero largo. Por ultimo, aplica el modulo respecto a principal. El modulo produce
//un entero de 0 a ( principal - 1);

int hash( char c[ ])
    {

    int i;
    long transf;

    for( i = 0; i < strlen( c); i++)
        c[ i] = toupper( c[ i]);
    transf = transformaclave( c);
    return  transf % principal;     //Recordar que principal esta difinido en el define
    }//fin_hash
//************************************************************************************************


//FUNCION TRANSFORMACLAVE*************************************************************************

long transformaclave( const char* cl)
    {
    int j;
    long d;

    d = 0;
    for( j = 0; j < strlen( cl); j++)
        {
        d = d * 27 + cl[ j];
        }
        //Si d supera el maximo entero largo, genera un numero negativo
        if( d < 0) d = -d;
        return d;
    } //fin_tranformaclave
//************************************************************************************************


//FUNCION ESCRIBIR********************************************************************************

void escribir( clave cla)
    {
    printf( "Tipo de cuenta: %s\t", cla.tipo_cta);
    printf( "Nombre de usuario: %s\t", cla.nomb);
    printf( "Password: %s\n", cla.pass);
    } //fin_escribir
//************************************************************************************************

Recommended Answers

All 7 Replies

what compiler are you using? I just compiled with VC++ 2005 Express and got no such error message, although I did get several others because you tried to make the return value of sizeof operator negative. Just typecase sizeof to return int and that corrects that problem.

Dev-C++ doesn't have a problem compiling it.

void main should be int main( void )


Also I don't understand why you didn't prototyped the function as you declared.

long transformaclave( const char* cl)
long transformaclave( const char c[ ]);

It appears to me that your compiler doesn't like that.

what compiler are you using? I just compiled with VC++ 2005 Express and got no such error message, although I did get several others because you tried to make the return value of sizeof operator negative. Just typecase sizeof to return int and that corrects that problem.

Hi! I'm using borland C++ 4.5, and says literally: "error ABPASS.CPP 358: 'transformaclave( const char*)' cannot be distinguished from 'transformaclave( const char* const)'. Also, there's some warnings.

i ve a dubt: look:

long transformaclave( const char* cl) <- im passing const char* cl from as parameter from hash function. Now look at hash function:
int hash( char c[ ]) (is the prototype) and :
long transf;
transf = transformaclave( c);

is correct pass c as a constant to transformaclave? if not, ¿how can i repair it??? thanks a lot and sorry for my bad english :)!

what compiler are you using? I just compiled with VC++ 2005 Express and got no such error message, although I did get several others because you tried to make the return value of sizeof operator negative. Just typecase sizeof to return int and that corrects that problem.

Hi! I'm using borland C++ 4.5, and says literally: "error ABPASS.CPP 358: 'transformaclave( const char*)' cannot be distinguished from 'transformaclave( const char* const)'. Also, there's some warnings.

i ve a dubt: look:

long transformaclave( const char* cl) <- im passing const char* cl from as parameter from hash function. Now look at hash function:
int hash( char c[ ]) (is the prototype) and :
long transf;
transf = transformaclave( c);

is correct pass c as a constant to transformaclave? if not, ¿how can i repair it??? thanks a lot and sorry for my bad english :)!

Dev-C++ doesn't have a problem compiling it.

void main should be int main( void )


Also I don't understand why you didn't prototyped the function as you declared.

long transformaclave( const char* cl)
long transformaclave( const char c[ ]);

It appears to me that your compiler doesn't like that.

THANKSSSSSS AIA!!!!!!! works fine now! thanks again you save my life :) :)

No hay de que!

you might try typecasting, like this:

transf = transformaclave( (const char*)c);

[edit]Sorry, I didn't see other posts before I posted this. Just ignore me since the problem is already solved.[/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.