data recall from a structure

This is a discussion on data recall from a structure within the C Programming forums, part of the General Programming Boards category; Hi I have only been coding C for a week or so. I am trying to code A program for ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    9

    data recall from a structure

    Hi I have only been coding C for a week or so. I am trying to code A program for a university assignment. It is based around flight planning. We have to read in the data from two text files and then use this information and a supplied set of functions to say if flights are possible etc. I have read in the aircraft data file with no worries, but when it comes to the airport information, the program craps out. I have used the debugger (using netbeans) and it seems that when calling an int back from the structure I have used it assigns it as 8 rather than 2.

    I have now sat for three hours just playing with it and have no idea why this is happening. I am using code that works elsewhere in my program.

    I am reasonably proficient in java but as mentioned before I have only been learning C for a week or so, and it has got me beat.

    any suggestions on why this is happening would be more than appreciated.

    the text files we have been given can be found here



    here is my code



    plane_structure.h

    contains the plane structure

    Code:
    /* 
     * File:   plane_structure.h
     * Author: Tone
     *
     * Created on 04 December 2009, 13:27
     */
    
    #ifndef _PLANE_STRUCTURE_H
    #define	_PLANE_STRUCTURE_H
    
    #ifdef	__cplusplus
    extern "C" {
    #endif
    
    /*
         * Structure for baggage information
         *
         */
        typedef struct _baggage_info{
            int maximum_baggage_weight;
            float arm;
        }baggage_info;
    
        /*
         * Structure for seat information
         *
         */
    
        typedef struct _seat_info {
            int seats_in_row;
            float arm;
        }seat_info;
    
        typedef struct _fuel_info {
            int maximum_fuel_weight;
            float arm;
            char name_of_fuel[50];
            int fuel_used_per_hour;
        }fuel_info;
    
    
        typedef struct _plane {
           char ident[100];
           char name[100];
           int  maximum_take_off_wieght;
           int  takeoff_dimension;
           int  max_landing_weight;
           int  landing_dimension;
           int  basic_wieght;
           float  basic_arm;
           int  seat_rows;
           seat_info seats[50];
           int  baggage_locations;
           baggage_info baggage[50];
           fuel_info fuel;
           int cruise;
    
    
         }plane;
    
    
    
    #ifdef	__cplusplus
    }
    #endif
    
    #endif	/* _PLANE_STRUCTURE_H */
    plane_data_manipulation

    this file works great

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include "plane_structure.h"
    
    
    
    FILE *fr;
    
        
    char temp[100];
    
    
    
    plane aircraft[100];
    plane foundAircraft;
    
    int count=0;
    
    
    void get_aircraft_filename(){
        char filename[BUFSIZ];
        char *p;
        printf("Please enter the name of the file containing the aircraft data\n\n"
               "Filename: ");
        //scanf("%s",&filename);
        if(fgets(filename, sizeof filename, stdin) != NULL){
            if ((p = strchr(filename, '\n')) != NULL)
                *p = '\0';
            fr = fopen (filename, "rt");
        }
        if(fr==NULL){
            printf("ERROR: file \"%s\" does not exist!\n\n",filename);
            get_aircraft_filename();
        }
        load_plane_data();
    }
    
    load_plane_data(){
    
    
        int i;
        char seatInfo[5];
        
        while(fgets(temp,100,fr) != NULL){
            
            strcpy(aircraft[count].ident,&temp[7]);
            fgets(temp,100,fr);       
            strcpy(aircraft[count].name,&temp[6]);
            fgets(temp,49,fr);
            strcpy(temp,&temp[6]);
            aircraft[count].maximum_take_off_wieght=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[4]);
            aircraft[count].takeoff_dimension=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[6]);
            aircraft[count].max_landing_weight=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[4]);
            aircraft[count].landing_dimension=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[4]);
            aircraft[count].basic_wieght=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[4]);
            aircraft[count].basic_arm=atoff(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[10]);
    
            
            aircraft[count].seat_rows=atoi(temp);
            char *token;
            char *line = temp;
            char *search = " ";
            for(i=0;i<aircraft[count].seat_rows;i++){
                int inner=0;
                fgets(temp,49,fr);
                char *seat_line=temp;
                token=strtok(seat_line,search);
                aircraft[count].seats[i].seats_in_row=atoi(token);
                
    
                token=strtok(NULL,search);
                aircraft[count].seats[i].arm=atoff(token);
    
            }
            fgets(temp,49,fr);
            strcpy(temp,&temp[9]);
            aircraft[count].baggage_locations=atoi(temp);
            for(i=0;i<aircraft[count].baggage_locations;i++){
                int inner=0;
                fgets(temp,49,fr);
                for(inner=0;inner<3;inner++){
                    if(temp[inner]==' ')break;
                    seatInfo[inner]=temp[inner];
                    aircraft[count].baggage[i].maximum_baggage_weight=atoi(seatInfo);
                }
    
                strcpy(temp,&temp[inner]);
                aircraft[count].baggage[i].arm=atoff(temp);
            }
    
    
            //fuel
            char fuelChars[5];
            int fuelCount=0;
            fgets(temp,49,fr);
            strcpy(temp,&temp[6]);
            //get the first bit
            
    
            
            
            char *fuel_line = temp;
            
    
    
            /* Token will point to "LINE". */
            token = strtok(fuel_line, search);
            aircraft[count].fuel.maximum_fuel_weight=atoi(token);
            /* Token will point to "TO". */
            token = strtok(NULL, search);
            aircraft[count].fuel.arm=atoff(token);
            token = strtok(NULL, search);
    
            
            strcpy(fuelChars,fuelChars);
            strcpy(aircraft[count].fuel.name_of_fuel,token);
            strcpy(temp,&temp[fuelCount]);
            aircraft[count].fuel.fuel_used_per_hour=atoi(temp);
            fgets(temp,49,fr);
            strcpy(temp,&temp[8]);
            aircraft[count].cruise=atoi(temp);
            fgets(temp,49,fr);
            count++;
        }
        strcpy(aircraft[count].ident,"END");
        fclose(fr);
    }
    
    void print_aircraft_info(){
        
        int i;
        int counter;
        for(counter=0;counter<count;counter++){
            printf("Aircraft: %d\n",counter);
            printf("Ident:   %s",aircraft[counter].ident);
            printf("Name:    %s",aircraft[counter].name);
            printf("MTOW:    %d\n",aircraft[counter].maximum_take_off_wieght);
            printf("TD:      %d\n",aircraft[counter].takeoff_dimension);
            printf("MXLW:    %d\n",aircraft[counter].max_landing_weight);
            printf("LD:      %d\n",aircraft[counter].landing_dimension);
            printf("BW:      %d\n",aircraft[counter].basic_wieght);
            printf("BA:      %f\n",aircraft[counter].basic_arm);
            printf("SeatRows %d\n",aircraft[counter].seat_rows);
            for(i=0;i<aircraft[counter].seat_rows;i++){
                printf("%d %f\n",aircraft[counter].seats[i].seats_in_row,aircraft[counter].seats[i].arm);
            }
            printf("Baggage: %d\n",aircraft[counter].baggage_locations);
            for(i=0;i<aircraft[counter].baggage_locations;i++){
                printf("%d %f\n",aircraft[counter].baggage[i].maximum_baggage_weight,aircraft[counter].baggage[i].arm);
            }
            printf("Fuel: %d %f %s %d\n",aircraft[counter].fuel.maximum_fuel_weight,aircraft[counter].fuel.arm,aircraft[counter].fuel.name_of_fuel,aircraft[counter].fuel.fuel_used_per_hour);
            printf("Cruise speed: %d",aircraft[counter].cruise);
        }
    }
    
    void print_found_aircraft(){
        int i;
        printf("Aircraft found:\n");
        printf("Ident:         %s",foundAircraft.ident);
        printf("Name:          %s",foundAircraft.name);
        printf("MTOW:          %d\n",foundAircraft.maximum_take_off_wieght);
        printf("TD:            %d\n",foundAircraft.takeoff_dimension);
        printf("MXLW:          %d\n",foundAircraft.max_landing_weight);
        printf("LD:            %d\n",foundAircraft.landing_dimension);
        printf("BW:            %d\n",foundAircraft.basic_wieght);
        printf("BA:            %f\n",foundAircraft.basic_arm);
        printf("SeatRows:      %d\n",foundAircraft.seat_rows);
        for(i=0;i<foundAircraft.seat_rows;i++){
            printf("seats per row: %d\narm of seats:  %f\n",foundAircraft.seats[i].seats_in_row,foundAircraft.seats[i].arm);
        }
        printf("Baggage: %d\n",foundAircraft.baggage_locations);
        for(i=0;i<foundAircraft.baggage_locations;i++){
            printf("%d %f\n",foundAircraft.baggage[i].maximum_baggage_weight,foundAircraft.baggage[i].arm);
        }
        printf("Fuel: %d %f %s %d\n",foundAircraft.fuel.maximum_fuel_weight,foundAircraft.fuel.arm,foundAircraft.fuel.name_of_fuel,foundAircraft.fuel.fuel_used_per_hour);
        printf("Cruise speed: %d",foundAircraft.cruise);
    }
    
    void find_aircraft_by_ident(char ident[]){
        int counter;
        for(counter=0;counter<count;counter++){
            char temp[7];
            strcpy(temp,aircraft[counter].ident);
            int diff=strcmp(temp, ident);
            if(diff==0){
                foundAircraft=aircraft[counter];
                print_found_aircraft();
                return;
            }
        }
        printf("ERROR: Plane not found\n\n");
        
    }
    
    void find_aircraft_by_name(char name[]){
        int counter;
        for(counter=0;counter<count;counter++){
            char temp[11];
            strcpy(temp,aircraft[counter].name);
            int diff=strcmp(temp, name);
            if(diff==0){
                foundAircraft=aircraft[counter];
                print_found_aircraft();
                return;
            }
    
        }
    
        printf("ERROR: Plane not found\n\n");
        
    }
    airport_data_manipulation

    this is the file with problems

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    /* Define the runway structure */
    
    typedef struct _runway{
        char runway_designator[50];
        int length_in_feet;
    }runway;
    
    /* Define the airport structure */
    
    typedef struct _airport{
        char letter_code[6];
        char name[20];
        float latitude;
        float longitude;
        int number_of_runways;
        runway runways[30];
        int number_of_fuels;
        char fuels[30][30];
    }airport;
    
    FILE *fr;
    char filename[100];
    airport airports[100];
    int count;
    char temp[100];
    
    get_airport_filename(){
        printf("Please enter the name of the file containing the airport data\n\n"
               "Filename: ");
        scanf("%s",&filename);
        fr = fopen (filename, "rt");
        if(fr==NULL){
            printf("ERROR: file \"%s\" does not exist!",filename);
            get_airport_filename();
        }
        load_airport_data();
    }
    
    load_airport_data(){
        int i;
        count=0;
        char info[5];
        
    
        while(fgets(temp,100,fr) != NULL){
        //    fgets(temp,100,fr);
            strcpy(airports[count].letter_code,temp);
            fgets(temp,100,fr);
            strcpy(airports[count].name,temp);
            fgets(temp,100,fr);
            airports[count].latitude=atoff(temp);
            fgets(temp,100,fr);
            airports[count].longitude=atoff(temp);
            fgets(temp,100,fr);
            airports[count].number_of_runways=atoi(temp);
            fgets(temp,100,fr);
            int outer;
            for(outer=0;outer<airports[count].number_of_runways;outer++){
                char *token;
                char *line = temp;
                char *search = " ";
    
                token=strtok(line,search);
                strcpy(airports[count].runways[outer].runway_designator,token);
                strcpy(temp,&temp[6]);
                airports[count].runways[outer].length_in_feet=atoi(temp);
    
            }
            outer=0;
            fgets(temp,100,fr);
            airports[count].number_of_fuels=atoi(temp);
    
        
            //here is where the problem is
            //for some reason the number that comes back from       
            //airports[count].number_of_fuels on the second loop
            //of the main loop returns 8 instead of two. Yet if you break the prog
            //and check inside the structure it is clearly 2
    
            for(outer=0;outer<airports[count].number_of_fuels;outer++){
                
                fgets(temp,100,fr);
                strcpy(airports[count].fuels[outer],temp);
                outer++;
            }
            outer=0;
            fgets(temp,100,fr);
            count++;
        
        
        }
        
        
        fclose(fr);
    }
    
    print_airport_info(){
        int counter=0;
        for(counter=0;counter<count;counter++){
    
            printf("Code:              %s",airports[counter].letter_code);
            printf("Name:              %s",airports[counter].name);
            printf("Latitude:          %f\n",airports[counter].latitude);
            printf("Longitude:         %f\n",airports[counter].longitude);
            printf("Number of runways: %d\n", airports[counter].number_of_runways);
            int i;
            for(i=0;i<airports[counter].number_of_runways;i++){
                printf("%s %d\n",airports[counter].runways[i].runway_designator,airports[counter].runways[i].length_in_feet);
            }
            printf("Number of fuels:   %d\n",airports[counter].number_of_fuels);
            for(i=0;i<airports[counter].number_of_fuels;i++){
                printf("%s",airports[counter].fuels[i]);
            }
            counter++;
        }
    
    }
    
    print_found_airport(){
    
    }
    main

    Code:
    /* 
     * File:   main.c
     * Author: tone
     *
     * Created on 03 December 2009, 22:32
     */
    
    #include <stdio.h>
    #include <stdlib.h>
    
    
    
         
    int main() {
    
        //get_aircraft_filename();
        get_airport_filename();
        //print_airport_info();
        //print_menu();
      
        return (EXIT_SUCCESS);
    }

    all comments greatly appriciated.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by m1cha3l View Post
    I have used the debugger (using netbeans) and it seems that when calling an int back from the structure I have used it assigns it as 8 rather than 2.
    Right, so you know exactly where the problem is, but rather than posting just the relevant code and the exact error from the debugger, you expect someone else to go thru several hundred lines, fit it all together, and then deduce where the problem is based on a very lame clue that involves your interpretation of some error message?

    Maybe that person will come along, some day.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    I apologise if that was the wrong thing to do! I assumed it would be better to give as much info as possible!


    the part of the code is in the airports_data_manipulation file and is commented
    Last edited by m1cha3l; 12-05-2009 at 11:53 AM.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    So do what was suggested and post the specific problem, i.e. a few lines of code that reproduces the problem and highlight (bold or colour) the specific line that you think is the source of the problem.

    You can reduce the majority of this code to reproduce the problem without having all of the other stuff to get in the way. Make a copy of your current project and remove every line that is irrelevant, i.e. print statements and variables that are unrelated to the problem. Then post this modified and shortened copy of your code which reproduces the problem. Then we can start with something. The longer you delay this suggestion, I think the longer you will have to wait for an answer.

  5. #5
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    ok here is the function

    the problem peice of code is highlighted

    my apologies once again

    Code:
    load_airport_data(){
        int i;
        count=0;
        char info[5];
        
    
        while(fgets(temp,100,fr) != NULL){
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            airports[count].number_of_runways=atoi(temp);
            fgets(temp,100,fr);
            int outer;
            for(outer=0;outer<airports[count].number_of_runways;outer++){
                char *token;
                char *line = temp;
                char *search = " ";
    
                token=strtok(line,search);
                strcpy(airports[count].runways[outer].runway_designator,token);
                strcpy(temp,&temp[6]);
                airports[count].runways[outer].length_in_feet=atoi(temp);
    
            }
            fgets(temp,100,fr);
            airports[count].number_of_fuels=atoi(temp);
            
            for(outer=0;outer<airports[count].number_of_fuels;outer++){
                
                fgets(temp,100,fr);
                strcpy(airports[count].fuels[outer],temp);
                
            }
            fgets(temp,100,fr);
            count++;
        
        
        }
        
        
        fclose(fr);
    }

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I have read in the aircraft data file with no worries, but when it comes to the airport information, the program craps out.
    What does "program craps out" mean? Does the program hang and is not responsive? Does it exit with no message? Does it crash and give a "segfault" or some error? If so, say what error and on exactly what line. Also, all of your functions should have a return type and return statement, otherwise there not "really" functions (none of yours have input or output).

    I have used the debugger (using netbeans) and it seems that when calling an int back from the structure I have used it assigns it as 8 rather than 2
    What does "calling an int back from the structure" mean? On what line is this happening?

    I hope you are starting to realize that if you are explicit and precise when describing your problem, you will get relevant and timely answers. If you dont try to help us help you and dont explain properly or vaguely, its only hurting you!

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    One thing is you have declared fuels as
    Code:
        char fuels[30][30];
    then your writing to it as
    Code:
    fgets(temp,100,fr);
                strcpy(airports[count].fuels[outer],temp);
    which means your writing at most 100 characters to the variable that can store at most 30 characters. Can you try to read at most 30 instead of 100? Or increase the size of fuels to 100 characters instead of 30.

    EDIT: The code seems to have many potential problems, here is just one more example. You define
    Code:
        char letter_code[6];
        char name[20];
    then write to these fields with more data than it can hold
    Code:
            strcpy(airports[count].letter_code,temp); // letter code can hold up to 6 but your giving up to 100
            fgets(temp,100,fr);
            strcpy(airports[count].name,temp); // name can hold up to 20 but your giving up to 100
    Last edited by nadroj; 12-05-2009 at 12:18 PM.

  8. #8
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    the error is

    handle_exeptions: Error while dumping state (probably corrupted stack)


    when debugging i found that while the structure contains the integer 2

    this line for(outer=0;outer<airports[count].number_of_fuels;outer++) reacts as 8


    @nadroj

    altered that and it made no difference, but well spotted. Thank you

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    @nadroj

    altered that and it made no difference, but well spotted. Thank you
    Please see my edit in my previous post. Basically, you have a number of these similar issues with buffer overflows which is probably the cause of the errors. Go through all of your code to remove these overflows and try it again.

    Also, I dont think the code you have posted is what your running. I dont see how you can even compile any of this code. None of your functions have a return type or return statement. Also the file with your "main" doesnt even "#include" your other files, so it cannot call those functions. Please post your actual code.
    Last edited by nadroj; 12-05-2009 at 01:07 PM.

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    as stated in previous post. I have done exactly the same thing with the aircraft file and that works perfectly. No errors at all.

    and the files I originally posted are the files I am using. I am using netbeans and have copied and paste from there to here

  11. #11
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I dont care what your doing with the files Im not talking about--those also have errors. Your "main" file has an error in it because it doesnt include the other required files your using. Realize that if some piece of code "runs" does not mean it is correct.

    Edit the code to do the following
    Code:
        while(fgets(temp,100,fr) != NULL){
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            fgets(temp,100,fr);
            airports[count].number_of_runways=atoi(temp);
            // put a print statement here to show what number_of_runways, make sure its what you expect it to be
    Also here
    Code:
            fgets(temp,100,fr);
            airports[count].number_of_fuels=atoi(temp);
            // print statement for number_of_fuels to make sure its correct
    And let me know if these are correct, my guess is they arent.

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    i have already said that they are not! when the program runs it returns 8 from the structure but when stepping through the program if you look inside the data structure it says the value is 2.

    this is another reason i included all the data in my first post so you can see I assign the value 2 to the structure.

    and fair enough there are flaws with my code! but did you right perfect code from the moment you started? I do intend to write better code but this is my first program! I have on your advice now added the includes in the main file.
    Last edited by m1cha3l; 12-05-2009 at 12:42 PM.

  13. #13
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I never once judged your ability, so stop assuming that and becoming defensive. You have a problem and asked for help. Im saying that these things are the source of your problem. Your saying they are not the source.

    For the number_of_runways, add one more fgets before you read it, it appears your reading the wrong line. Your probably reading "08/26 3031" which gets interpreted as "08" or simply "8", but you mean to read the next line (or previous line, see next post).
    Last edited by nadroj; 12-05-2009 at 01:00 PM.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    You havent described the format of the input file, so all we can do is guess.
    Code:
    EGFA
    Aberporth
    52.115278
    -4.556944
    1 // if this is the number_of_runways, then the 5th read is this line
    08/26 3031
    2 // if this is the fuels, then the 7th read is this line
    100LL
    JA1
    So update your reads accordingly.

    Also, it seems the records are not uniform, i.e. the next one is this
    Code:
    EGCK
    Caernarfon
    53.104167
    -4.340278
    2
    02/20 3534
    08/26 2887
    2
    100LL
    JA1
    which is different from the previous one. This means you cant simply rely on the number of lines in the record, so you would need to do more parsing to determine which line is what.
    Last edited by nadroj; 12-05-2009 at 12:57 PM.

  15. #15
    Registered User
    Join Date
    Aug 2008
    Posts
    9
    I supplied a link to the text file provided.

    you where right i had a fgets in the wrong place.

    this is the method fixed.

    Code:
    void load_airport_data(){   
        count=0;
        char newline='\n';
    
        while(fgets(temp,20,fr) !=NULL){                                            // get the code
            if(strcmp(temp,&newline)==0)continue;
            strcpy(airports[count].letter_code,temp);                               // put code into variable in structure
            fgets(temp,20,fr);                                                      // gets name
            strcpy(airports[count].name,temp);
            fgets(temp,20,fr);                                                      // latitude
            airports[count].latitude=atoff(temp);
            fgets(temp,20,fr);                                                      // longitude
            airports[count].longitude=atoff(temp);
            fgets(temp,10,fr);                                                      // number of runways
            airports[count].number_of_runways=atoi(temp);                                                             //
            int outer;
            for(outer=0;outer<airports[count].number_of_runways;outer++){           //loop for number of runways
                fgets(temp,20,fr);                                                  // gets the runway line
                char *token;
                char *line = temp;
                char *search = " ";
                token=strtok(line,search);
                strcpy(airports[count].runways[outer].runway_designator,token);
                strcpy(temp,&temp[6]);
                airports[count].runways[outer].length_in_feet=atoi(temp);
            }
            fgets(temp,100,fr);                                                     //get the number of fuels
            airports[count].number_of_fuels=atoi(temp);
            for(outer=0;outer<airports[count].number_of_fuels;outer++){             //loop for number of fuels
                fgets(temp,100,fr);                                                 
                strcpy(airports[count].fuels[outer],temp);            
            }
            fgets(temp,10,fr);                                                      //read blank line
            count++;
        }    
        fclose(fr);
    }
    I also added a test at the begining as i discovered a double blank line in the file. so this deals with that.

    the includes you told me to put in the main file, is causing errors. this is the error

    Code:
    gcc -Werror    -o dist/Debug/Cygwin-Windows/cppapplication_1 build/Debug/Cygwin-Windows/airport_data_manipulation.o build/Debug/Cygwin-Windows/main.o build/Debug/Cygwin-Windows/plane_data_manipulation.o build/Debug/Cygwin-Windows/menu.o  
    build/Debug/Cygwin-Windows/main.o: In function `load_airport_data':
    /cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:36: multiple definition of `_load_airport_data'
    build/Debug/Cygwin-Windows/airport_data_manipulation.o:/cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:36: first defined here
    build/Debug/Cygwin-Windows/main.o: In function `get_airport_filename':
    /cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:75: multiple definition of `_get_airport_filename'
    build/Debug/Cygwin-Windows/airport_data_manipulation.o:/cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:75: first defined here
    build/Debug/Cygwin-Windows/main.o: In function `print_airport_info':
    /cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:87: multiple definition of `_print_airport_info'
    build/Debug/Cygwin-Windows/airport_data_manipulation.o:/cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:87: first defined here
    build/Debug/Cygwin-Windows/main.o: In function `print_found_airport':
    /cygdrive/c/Documents and Settings/tone/My Documents/NetBeansProjects/CppApplication_1/airport_data_manipulation.c:109: multiple definition of `_print_found_airport'
    I have no idea how to stop this. I even checked a reference book, C - in a nutshell, and couldnt find it. infact when they talk about multiple files they dont include them either!
    Quote Originally Posted by C - in a nutshell
    ........
    C supports modular programming by allowing you to organize a program in as many source and header files as desired, and to edit and compile them separately. Each source file generally contains functions that are logically related, such as the program's user interface functions. It is customary to label C source files with the filename suffix .c .

    Examples 1-2 and 1-3 show the same program as Example 1-1, but divided into two source files.

    Example 1-2. The first source file, containing the main( ) function
    // circle.c: Prints the areas of circles.
    // Uses circulararea.c for the math

    #include <stdio.h>
    double circularArea( double r );

    int main( )
    {
    /* ... As in Example 1-1 ... */
    }



    Example 1-3. The second source file, containing the circularArea( ) function
    // circulararea.c: Calculates the areas of circles.
    // Called by main( ) in circle.c

    double circularArea( double r )
    {
    /* ... As in Example 1-1 ... */
    }

    .......
    Am I just getting confused?

    I do appriciate your help and advice
    Last edited by m1cha3l; 12-05-2009 at 02:24 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 11:42 AM
  2. Data structure implementation
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 07-31-2003, 07:44 AM
  3. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM

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