| | |
Error listing files...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2004
Posts: 8
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jul 2004
Posts: 8
Reputation:
Solved Threads: 0
<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...
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...
![]() |
Similar Threads
- listing files on web page (VB.NET)
- Hard drive error while copying files (Windows NT / 2000 / XP)
- "Forbidden / You don't have permission to access / on this server." error (Linux Servers and Apache)
- listing all files on hard drive? (Windows NT / 2000 / XP)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- HDD Error, Corrupted? Need the files off it! (Storage)
Other Threads in the C++ Forum
- Previous Thread: Allegro, DirectX or...???
- Next Thread: ive got a Q
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





