Structure difficulties

This is a discussion on Structure difficulties within the C Programming forums, part of the General Programming Boards category; I get the error message: dereferencing pointer to incomplete type for every line where i use the code line: pointer->variableinstructure ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    49

    Structure difficulties

    I get the error message: dereferencing pointer to incomplete type
    for every line where i use the code line: pointer->variableinstructure

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    struct OUTPUT_DATA 
    {
           int C_num; 
           int P_num; 
           int B_num; 
           float Prix_C; 
           float Prix_B; 
           float Prix_P;
    };
    
    void Output_Data(struct OUTPUT_DATA *);
    
    int main()
    {
          //All my variables are declared, i double checked....
    
          struct OUTPUT_DATA NUM_COST;
         
          NUM_COST.C_num = ((sortieHeureMaxPanneaux / eff_conv) / 5) + 1;
          NUM_COST.B_num = ((Besoin / eff_conv) / 4.8) + 1;
          NUM_COST.P_num = Aire + 1;
          
          NUM_COST.Prix_C = NUM_COST.C_num * C$;
          NUM_COST.Prix_B = NUM_COST.B_num * B$;
          NUM_COST.Prix_P = NUM_COST.P_num * P$;
    
          Output_Data(NUM_COST);
    
          system("PAUSE");
          return 0;
    }
    
    void Output_Data(struct OUTPUT_DATA *NUM_COSTptr)
    {
          char article[3][29] = {"Batteries (4.8 V)","Convertisseurs (5 KW)","Panneaux photovoltaique (m^2)"};
          float $Total;
          
          printf("\nAfin d’installer un bloc d’alimentation &#233;lectrique photovolta&#239;que &#224; panneaux plats pour l’utilisation r&#233;sidentielle &#224; Ottawa, ON, vous aurez besoin de:\n\n");
          printf("&#37;d %s = %f", NUM_COSTptr->B_num, article[0], NUM_COSTptr->Prix_B);
          printf("\n%d %s = %f", NUM_COSTptr->C_num, article[1], NUM_COSTptr->Prix_C);
          printf("\n%d %s = %f", NUM_COSTptr->P_num, article[2], NUM_COSTptr->Prix_P);
          
          $Total = NUM_COSTptr->Prix_B + NUM_COSTptr->Prix_C + NUM_COSTptr->Prix_P;
          
          printf("\n\nCouts total: %f", $Total);
    }
    Last edited by Tyrant; 11-18-2007 at 12:29 PM.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    void Output_data(struct INPUT_DATA *NUM_COSTptr)
    struct INPUT_DATA is not defined . You defined a struct OUTPUT_DATA only.
    Kurt

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Quote Originally Posted by ZuK View Post
    Code:
    void Output_data(struct INPUT_DATA *NUM_COSTptr)
    struct INPUT_DATA is not defined . You defined a struct OUTPUT_DATA only.
    Kurt
    Im an idiot, it fixed prettymuchevrything.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Although now i get an error saying: incompatible type for argument 1 of `Output_Data'

    and its the very last error in my program......
    Last edited by Tyrant; 11-18-2007 at 12:28 PM.

  5. #5
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Output_Data(&NUM_COST);
    the function accepts only a pointer to a structure.

  6. #6
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    I dont know why that worked but ty.

    If mat[][]
    fonction(mat)

    I thought that if struct bla Hello;
    then
    fonction2(Hello)

    would be the same thing and that i would send the adresse of my structure as a parameter....

  7. #7
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    mat is an address because it was declared as an array...

    Code:
    char a = ' w'
    in this case a is not the address of the memory where there is 'w' but it is the value itself.
    instead &a is that address

    if you have
    Code:
    char a[1] = ' w'
    a is a pointer, so a is the the address of the memory where there is 'w' and *a is the value itself 'w'

  8. #8
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    Code:
    struct OUTPUT_DATA NUM_COST; //NUM_COST is your object 
     
    struct OUTPUT_DATA * addr = &NUM_COST; 
    //now addr points to (and is) the address of NUM_COST

  9. #9
    Registered User
    Join Date
    Nov 2007
    Posts
    49
    Thank very much again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Replies: 5
    Last Post: 02-14-2006, 08:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 04:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21