write aC++ program that would read from a CD and display information

Discussion in 'C++' started by munif, Dec 22, 2004.

  1. munif

    munif Guest

    i wnat write a C++ program that would read from a CD and display
    information about files and folders in the given CD

    In simple words you would be performing a simple (ls -l)[Linux] or (DIR
    /S)[DOS] on the CD.

    LOOk at this code


    /*
    CopyRight 2004 by Basit Qureshi

    The following code illustrates how to open an iso file and read
    its contents.

    Notice most numbers stored in the CD are in Big_Endian or
    Little_Endian format. For instance if a number is stored in
    8 bytes long memory this means the first 4 bytes represent
    the same number in Little_endian format and the other 4 bytes
    respresent the same number in big_endian format.
    */

    #include <iostream.h>
    #include <fstream.h>
    #include <stdlib.h>

    #define SECTOR_SIZE 2048
    ifstream fin;
    unsigned char buf[SECTOR_SIZE];

    unsigned char PTAddress[4];
    main()
    {
    fin.open("test2.iso");
    //goto locations 16 * sizeof SECTOR to read the PVD
    fin.seekg(16*sizeof(buf));
    //read 2048 bytes in buffer
    fin.read (buf,2048);
    PTAddress[0]= buf[140]; // first bit
    PTAddress[1]= buf[141]; //second bit
    PTAddress[2]= buf[142]; // thirdbit
    PTAddress[3]= buf[143]; //fourth bit

    //convert the above binary number to integer!! notice this is 4 bytes
    long
    // address = PTAddress[3] * 2^24 + PTAddress[2] * 2^16 +
    PTAddress[1] * 2^8 + PTAddress[0] * 2^0;
    double address = PTAddress[3] * 16777216 + PTAddress[2] * 65536 +
    PTAddress[1] * 256 + PTAddress[0] * 1;

    //goto location of the path table
    fin.seekg(address*sizeof(buf));
    //read the sector that contains the path table.
    fin.read(buf,2048);
    //read the description of the path table. We are concered with the
    location of the
    //first directory so...goto that location...!

    address = buf[5] * 16777216 + buf[4] * 65536 + buf[3] * 256 + buf[2] *
    1;

    fin.seekg(address*sizeof(buf));

    //read the directory record's sector!!
    fin.read(buf,2048);

    //now that the directory record is loaded you can find all the files and
    print
    //their parameters!
    fin.close();
    }




    please help me to complete this C++ code
     
    munif, Dec 22, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek Kurowski
    Replies:
    1
    Views:
    1,000
    Mark A. Odell
    Aug 18, 2004
  2. goosen_cug
    Replies:
    2
    Views:
    357
    Howard
    Jul 3, 2006
  3. hunglduc
    Replies:
    1
    Views:
    314
    RedGrittyBrick
    Feb 23, 2009
  4. Mmcolli00 Mom
    Replies:
    2
    Views:
    197
    Mmcolli00 Mom
    Jan 27, 2009
  5. sahm
    Replies:
    4
    Views:
    690
Loading...

Share This Page