943,917 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2430
  • C++ RSS
Aug 18th, 2004
0

Error listing files...

Expand Post »
Hi,
I'm trying to write an array of linked lists to disk using c++.I'm running this program on Linux.My data structures are as follows...

A Hashtable class which holds the array of linked lists...
A linked list class which also has a writetodisk function..
An indexer class which adds entries to one of 26(one for each alphabet) entries in the array of hashtable object (the hashtable object subsequently adds this entry to a given linked list.

All my classes are working fine in adding searching etc etc except for when i get down to writing to disk..In this case I am writing a few of the linked lists of the hashtable object to disk at a time then another few to another file and so on..
eg) My hashtable has 211 linked lists i write 5 at a time to one file and so on till i have written all 211 linked lists..

I do this for all my 26 hashtable objects.. My problem is that after writing a upto around 22 of these hashtable objects my 23rd is giving problems... it writes a few of its linked lists to disk and then gives me an error ie the ofstream object is null..I have posted the code below for my write function in my hashtable class .. If anyone could give me an idea where i'm going wrong i would appreciate it...

void hashtable::createbuck()
{
int i=0;
while(i<=HSIZE/NOLL) //HSIZE=211 the no of linked lists
{ //NOLL the number of linked lists written
string no; //at a time...
string path="ht/"; //to create the path...
path=path+letter+"/"; //letter is a member fn storing which //letter the hashtable refers to
itoa(i,no); //convert i to a string
path+=no;
path+=".gig";
//cout<<"PATH: "<<path<<endl; //the path is coming out fine
//check if dir ht exists if not create it and proceed...
DIR *p=opendir("ht/");
if(!p)
{
//need to create ht and subdirs..
mkdir("ht",S_IRUSR|S_IWUSR);
char ch;
for(int i=0;i<26;i++)
{
string d="ht/";
ch='a'+i;
d=d+ch;
mkdir(d.c_str(),S_IRUSR|S_IWUSR);
}
}
ofstream of(path.c_str());
if(!of)
{
cout<<"Hash:Error creating file.."<<endl;
return;
}
for(int j=0;j<NOLL;j++)
if(i*NOLL+j<HSIZE) //call thw writetofile fn for each
ht[i*NOLL+j].writetofile(of); //linkedlist
of.close();
i++;
}

}

A function in the indexer class calls this function for each of the 26 hashtable objects...
Thanks a ton,
Piyush
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crazybitez is offline Offline
8 posts
since Jul 2004
Aug 18th, 2004
0

Re: Error listing files...

Please put the code in [ code ] [ / code] tags... it'll be easier to read.

Where is the error about null ofstream happening?

Here?
ht[i*NOLL+j].writetofile(of); //linkedlist
Reputation Points: 17
Solved Threads: 1
Junior Poster
cosi is offline Offline
153 posts
since Aug 2004
Aug 18th, 2004
0

Re: Error listing files...

<code>
void hashtable::createbuck()
{
int i=0;
while(i<=HSIZE/NOLL) //HSIZE=211 the no of linked lists
{ //NOLL the number of linked lists written
string no; //at a time...
string path="ht/"; //to create the path...
path=path+letter+"/"; //letter is a member fn storing which //letter the hashtable refers to
itoa(i,no); //convert i to a string
path+=no;
path+=".gig";
//cout<<"PATH: "<<path<<endl; //the path is coming out fine
//check if dir ht exists if not create it and proceed...
DIR *p=opendir("ht/");
if(!p)
{
//need to create ht and subdirs..
mkdir("ht",S_IRUSR|S_IWUSR);
char ch;
for(int i=0;i<26;i++)
{
string d="ht/";
ch='a'+i;
d=d+ch;
mkdir(d.c_str(),S_IRUSR|S_IWUSR);
}
}
ofstream of(path.c_str());
if(!of)
{
cout<<"Hash:Error creating file.."<<endl;
return;
}
for(int j=0;j<NOLL;j++)
if(i*NOLL+j<HSIZE) //call thw writetofile fn for each
ht[i*NOLL+j].writetofile(of); //linkedlist
of.close();
i++;
}

}
</code>
My error is that after writing a few linked lists to disk the ofstream object of keeps returnin null...and thus "Hash:Error creating file" keeps occuring...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
crazybitez is offline Offline
8 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Allegro, DirectX or...???
Next Thread in C++ Forum Timeline: ive got a Q





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC