Anonymous asked in Computers & InternetProgramming & Design · 10 years ago

Can anyone give me an example of usage of direct access files containing structures in C++?

I have to write a Program that reads information from a file with direct access and change some stuff in it. ( I have to save info about students in this file )

4 Answers

  • 10 years ago
    Best Answer

    Direct access means that you can seek in a file according to an index file.

    1. file contains id, other i.e. human readable information, and an offset into the file

    2. file contains data with identical recordlengths

    So you would use the index file in order to identify the information you want to retrieve

    from the direct access file.

    // record structure for direct access

    struct Person {

    int id;

    char szName[30];

    char szAddress[60];



    struct PersonIDX {

    int id;

    char szName[15]; // to have an idea who this could be

    unsigned offset;


    In C you would use fread/fwrite, fseek and ftell in order to move around

    In C++ this would be an outline of an update function

    void update_patient()


    Person p;

    PersonIDX idx;

    fstream f1, f11;

    int person_no = 0; "person.dat" , ios::in|ios::out|ios::binary ); ( "personIDX.dat", ios::in|ios::binary );

    cout<<"Please enter Person ID to modify";



    if( {

    // get the update information










  • 3 years ago


    Source(s): Instant Telephone Reverse
  • 3 years ago

    the excellent 'debate' is what's a intense question? How do you gage somebody's sincerity? as quickly as you initiate off attempting to respond to questions like that then you definitely initiate off moving into censorship and whilst there are some aspects (to me) that are open and close no flow aspects in a public communicate board there are greater gray aspects then you definitely recognize. on the top of the day it truly is user-friendly adequate to pass questions which you do unlike, in actuality if greater people did that then there could be much less room for lots of the idiots/trolls who infect Yahoo solutions frequently. I relish non secular greater open ended questions the place there is a few room for debate or opinion. I save coming back, because of the fact I nonetheless discover it appealing how a majority of those people from diverse walks and a while of existence actual come at the same time and initiate off communicatings suggestions and ideology.

  • 10 years ago

    Research the following functions (a good spot would be

    - fopen(): open file for reading/writing/both

    - fscanf(): read from file

    - fprintf(): write to a file

    - fclose(): close the file that was opened by fopen()

    Define the structures, and then use those functions correctly to read/write the file.

Still have questions? Get your answers by asking now.