13 August 2011

Read n bytes from start of a large file

SA,

How are you all doing? I hope that you are doing well...

I was just playing.... ya playing...

I was trying to install Mac OS X on my new HP computer, I had an old MAC OS X iso file and when I try to use it from inside VMWare, it keep saying .. "No Operating System found!" so I need to know why??

I've bough a new DVD Disk and tried to burn that iso image but WIN 7 Burn program told me that the iso file is not in a valid format ...

So, I need to see how this iso file looks like...
I've tried to open this huge (4+ GB) iso file in np++, but this cause the np++ to hang .. so I need to read the first n bytes from the file and see how these bytes looks like..

I am a Java programmer with little knowledge in C/C++. But I wanted to write this program in CPP...

It reads starting from a random byte to 10000 bytes from the iso file and write to some arbitrary file on the FS..

Here's the source code:


  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6. 
  7. int main(void)
  8. {
  9.     ifstream f;
 10.     ofstream out;
 11.     f.open("D:\\Programs\\mac\\Mac OS X\\Mac OS X 10.4.8 [JaS AMD-Intel-SSE2-SSE3 with PPF1].iso", fstream::in);
 12.     out.open("D:\\mac.out.txt", fstream::out);
 13.     
 14.     srand(time(NULL));
 15.     int start = rand(); 
 16.     cout << "start reading fomr byte: " << start << endl;
 17.     
 18.     char c = 0;
 19.     for (int i=start; i < start + 10000; i++)
 20.     {
 21.         f >> c;
 22.         out <<c;
 23.     }
 24.        
 25.     f.close();
 26.     out.close();
 27.     
 28.     return 0;
 29. }

Hence I am not a CPP Guru, I've used cplusplus.com as API reference..

No comments: