How to read a file using hash table

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 7
Reputation: doublebond is an unknown quantity at this point 
Solved Threads: 0
doublebond doublebond is offline Offline
Newbie Poster

How to read a file using hash table

 
0
  #1
Jul 7th, 2009
Hi Guys,

Please help me in doing this.

I am trying to read a file using fstream, but my prof wants me to do the same using hash table, which i have know idea. Please tell me hw can i do the same.

The file contains huge data like the size of the block and its respective data.

Please find the code below.

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <string>
  5. #include <algorithm>
  6.  
  7.  
  8. using namespace std;
  9. using std::ifstream;
  10. using std::ostream;
  11. using std::cout;
  12.  
  13. int MAX_LENGTH = 0;
  14. int N = 1;
  15.  
  16. class Entropy
  17. {
  18. public:
  19.  
  20. void readData();
  21. void process();
  22. // void write();
  23. ifstream fin;
  24. ofstream fout;
  25.  
  26. };
  27.  
  28. int main()
  29. {
  30. Entropy zero_order;
  31. zero_order.readData();
  32. }
  33.  
  34.  
  35. void Entropy::readData()
  36. {
  37. int n;
  38. char next;
  39. cout << "We are about to read the data from the trace.txt";
  40.  
  41. cout<<"\n\nHow many bits do you want to read?";
  42. cin>>n;
  43.  
  44. fin.open("trace.txt");
  45. fout.open("dude.txt");
  46.  
  47. if(fin.fail())
  48. {
  49. cout<<"Opening the input file failed\n";
  50. exit(1);
  51. }
  52.  
  53. fin.get(next);
  54. fout<<next;
  55. n--;
  56.  
  57. while(n != 0)
  58. {
  59. fin.get(next);
  60. fout<<next;
  61. n--;
  62. }
  63. fin.close();
  64. fout.close();
  65.  
  66. }

Cheers
Last edited by Ancient Dragon; Jul 7th, 2009 at 12:39 am. Reason: correct code tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: How to read a file using hash table

 
0
  #2
Jul 7th, 2009
I don't see a hash table to read from...

Create a hash function according to your needs and have a look at some standard hashing functions.Once you have a hashing function pass the key parameter of the data you want to write to hashing function and get the hash value corresponding to it.And you can open the file and move the filepointer to the location of your hash value and write the data there. Thats it. Later when you want to look for the data you just need to generate the hash value and corresponding position of data.

This ofcourse is only one among the several ways you can use a hashing.
Last edited by csurfer; Jul 7th, 2009 at 12:44 am.
I Surf in "C"....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC