1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Rep Power

    Please help with struct and call from text file

    hi all , please help me to write 2 function

    typedef struct
    code flight[2];
    int num_sit;
    int date;
    }flight ;

    how i doing :
    1.write function to take "text file" ? and write flight data?
    2. call the flight data text file and printf code flight that the sit that availbale
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    To answer the question we'd need to know the definition of

    I can make sense of Name and destination only as poorly chosen macros, such as

    #define Name char passenger_name

    We'd need sample input text file and how it relates to the struct, (this might be subtle, how does an int express a date?)

    We'd need to know how the output file should look

    We might need a database of plane types and passengers to handle the "sits".

    We most of all need to see your programming effort with explanation of the problems you encounter. This will give us a willingness to consider your thread.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    I think we might also have a language barrier at work here. Kind of a common thing to have happen.

    In a slightly older and more structured terminology, a database table is divided into records. Each record contains the information about a single item in that database table.

    In programming, many languages (eg, Pascal) refers to each single item as a RECORD. In C, it's a struct. A file of records would therefore be a file of struct's. The flight struct that you defined is therefore one record. And the file is the collection of all such records.

    In a simple hierarchical manner:
    1 file consists of many records.
    1 record consists of many fields.
    Each field is a distinct data item.

    When using a text file to hold records, each record occupies one single line in the file.

    Each record contains the fields that are defined in your struct. The fields are separated by a delimiter (HINT: look that term up! It means something very important and is something that we will talk about so you had better understand it!). That delimiter is often a comma, though if a field is a string that could contain a comma, then that string needs to be quoted.

    I must assume that you have been given a text file to use, so whatever its formatting is is the formatting that your program must conform to. At this point, all I could possibly do would be to guess at how it might possibly be formatted.

    Originally Posted by tsahar
    how i doing :
    1.write function to take "text file" ? and write flight data?
    2. call the flight data text file and printf code flight that the sit that availbale
    "text file" should be the char string that contains the name of the text file that contains the data. You should use that char string to open that text file, which you would then read one record at a time, extracting each record's data from its fields, and then printing that data out as appropriate. You say, "that the sit that availbale". We do not understand what that is supposed to mean. There is a num_sit field. Does that you are supposed to only output information for those records whose num_sit field was equal to a particular value? If so, then OK: if num_sit equals the right value(s), then output that record, else don't.

IMN logo majestic logo threadwatch logo seochat tools logo