Thread: struct,pointer and file

  1. #1
    gatli
    Guest

    struct,pointer and file

    hi,

    struct bike
    {
    char manuf[25];
    int id;
    bool rcode;
    char customer[25];
    int size;
    float rentcoast;
    bike *manufP;
    bike *idP;
    };
    int main( )
    {
    bike *temp;
    int code;
    char ch[20];
    ifstream filestr;
    filestr.open("lib/lab1.dat");
    ......
    ......
    }

    I want to write a function that will allocate storage for a new bike struct (a new node), read the data for the bike data members from a file named lib/lab1.dat, and return a pointer to the new node.
    how can I write this function?

    thanks.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You can allocate memory with the 'new' keyword and the read the file with filestr.get()/filestr.getline() etc.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM