/
Inicio :: Foros

 F.A.Q.F.A.Q.                  Conéctese para revisar sus mensajesConéctese para revisar sus mensajes   

Problema con accceso a estructuras.

 
      Índice del Foro elrincondelc.com -> C/C++ en General
Ver tema anterior :: Ver siguiente tema  
AutorMensaje
chemaspain



Registrado: 27 Nov 2010
Mensajes: 4

MensajePublicado: 06/05/2011 9:21 am
Título: Problema con accceso a estructuras.

Hola a todos.

Estoy muy agobiado con una practica de programacion que debo entregar pronto y no se como resolver un problema leve que me ha surgido que me tiene muy atrancado, a ver si me podeis echar un cable y ayudarme. Esta es la funcion y la definicion de la estructura:
Código:


typedef struct tSupplier{
   int idSupplier;
    tString name;
    tString addr;
    int phone[MAX_PHONE];
    struct tFurniture *firstFur,*currFur;                               
    float profitMargin;
} tSupplier;
 
typedef struct {
   int idFurniture;
   int idSup;
   tString nameFur;
   float sizes[MAX_SIZES];
   tString typeFur;
   tColor color;
   float costPrice;
   float retailPrice;
   int deliveryTime;
   struct tFurniture *prevFur, *nextFur;                               
   struct tFurniture *prevFurType, *nextFurType;
} tFurniture;
 
........
 
void fur_get_name (tFurniture f, tString n)
{
     strcpy (n,f.nameFur);       
}
 
.......
 
void sup_set_profitMargin (tSupplier *s, float r)
{
     tString name;
     float price;
 
     s->profitMargin = r;
 
     s->currFur=s->firstFur;
     if (s->currFur!=NULL)
        {
             sup_get_name(*s,name);
             printf("-----------------------------------------------------------------");
             printf("Supplier: %s \n",name);
 
             if (s->idSupplier == s->currFur->idSup) /* Aqui me da el primer error de dereferencing  */
                       s->currFur->retailPrice = s->profitMargin * s->currFur->costPrice;
             while (s->currFur!=NULL)
                   {
                        fur_get_name(s->currFur,name); /* Aqui me da el error de incompatible tipo de argumento en parametro 1*/
                        printf("Furniture: %s \t",name);
 
                        price=fur_get_retailPrice(s->currFur);
                        printf("Old retail price: %d \t", price);
 
                        s->currFur->retailPrice = s->profitMargin * s->currFur->costPrice;
 
 
                        price=fur_get_retailPrice(s->currFur);
                        printf("New retail price: %d \n", price);
 
                        s->currFur=s.currFur->nextFur;
                   }
             printf("-----------------------------------------------------------------");
        }
}


El caso es que me da el derreferencing ese tipico de las estructuras mal leidas pero es que he probado de todo y no se como solucinarlo. Si alguien me guiara en como acceder a la estructura, en las líneas marcadas con los comentarios, solo hay dos, le estaría enormemente agradecido. El resto ya las resolvería yo, por que son iguales.

Gracias.

Saludos.
Chema.
Volver arriba
polly



Registrado: 19 Jul 2007
Mensajes: 618

MensajePublicado: 06/05/2011 10:52 am
Título:

Podrías subir todo el código ? Porque sin compilarlo va a ser difícil.


s2
Volver arriba
chemaspain



Registrado: 27 Nov 2010
Mensajes: 4

MensajePublicado: 06/05/2011 11:26 am
Título:

Ya he descubierto por que me daba el fallo de dereferencing ese que indico en el primer comentario. Era simplemente por que se me paso poner nombre a la estructura en cuestion :

Código:
typedef struct {
   int idFurniture;
   int idSup;
   tString nameFur;
   float sizes[MAX_SIZES];
   tString typeFur;
   tColor color;
   float costPrice;
   float retailPrice;
   int deliveryTime;
   struct tFurniture *prevFur, *nextFur;                               
   struct tFurniture *prevFurType, *nextFurType;
} tFurniture;


Eso debia ser así:

Código:
typedef struct tFurniture{
   int idFurniture;
   int idSup;
   tString nameFur;
   float sizes[MAX_SIZES];
   tString typeFur;
   tColor color;
   float costPrice;
   float retailPrice;
   int deliveryTime;
   struct tFurniture *prevFur, *nextFur;                               
   struct tFurniture *prevFurType, *nextFurType;
} tFurniture;


Por un lado, una cosa solucionada, pero aun queda el otro fallo que indique en mi primer mensaje, ¿como puedo enviar ese parametro primero que me da un error de que no coinciden los tipos, ya que es enviado como puntero si realmente me esta pidiendo que le envie un parametro de tipo tFurniture? Tened en cuenta que no puedo modificar la cabecera de las funciones.

Gracias.

Saludos.
Chema.
Volver arriba
      Índice del Foro elrincondelc.com -> C/C++ en General
Página 1 de 1Todas las horas están en GMT - 8 Horas

 
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas

(c) ElRincondelC.com

Un proyecto de UrlanHeat.com