i've created a linked list which stores some info about documents
such as code,title,creator,filename,...
i've also stored some info about some other documents in a *.txt file
i've got a search function in my program that gets a code from the user and
tries to find that code either in the file or in the linked list....when it searches the
linked list it works alright and gives all the other info of that document, however
when searching the file, the program runs an error and ends
also, i cannot write more than one series of information at a time on the file
can u help?
refs::refs()
{
next=NULL;
first=last=NULL;
f.open("refs.txt", ios::in|ios::out|ios::app|ios::binary);
cout<<"\nEnter the properties of the document in the following order : "<<endl;
cout<<"\n\t Code: "<<endl;
cin>>code;
int l=strlen(code);
f<<"\n";
f.write((unsigned char*)code,l);
f<<"\t";
cout<<"\n\t Title: "<<endl;
cin>>title;
int l1=strlen(title);
f.write((unsigned char*)title,l1);
f<<"\t";
}
void refs::search()
{
char cd[6];
char ttl[40];
char cr[40];
char lc[100];
char fn[60];
char kw[40];
char cm[255];
char s;
while(1)
{
cout<<"\n\nPlease determine how you want to search :";
cout<<"\nTo search by Code press 'c'\nTo search by Title press 't'\nTo search by Creator press 'r'";
cout <<"\nTo search by Location press 'l'\nTo search by file name press 'n'\n";
cout <<"To search by Keyword press 'k'\nTo search by Comment press 'm'\n"<<endl;
cin>>s;
char str[200];
refs *ptr;
ptr=first;
while(ptr){
switch(s)
{
case 'c':
{
cout<<"\nPlease enter the Code you want to search for: "<<endl;
cin>>cd;
int len=strlen(cd);
for(int ii=0; ii<len ;ii++)
{ if(ptr->code[ii]==cd[ii])
{
cout<<endl<<"*****Code found in the list .\n";
cout<<endl<<"**************************";
cout<<"Here is the full information of the document: "<<endl;
cout<<"\n\tCode :"<<ptr->code<<"\n \tTitle : "<<ptr->title<<"\n\tCreator : "<<ptr->creator;
cout<<"\n\tLocation :"<<ptr->location<<"\n \tFile Name : "<<ptr->filename<<"\n\tKeyword : "<<ptr->keyword;
cout<<"\n\tComment "<<ptr->comment;
cout<<endl<<"**************************";
break;
}
ptr=ptr->next;
}
while (f.getline(str,120))
{
int lenn=strlen(str);
for(int j=0;j<lenn;j++)
if(cd[j]==str[j])
{
cout<<endl<<"*****Code found in the list .\n";
cout<<endl<<"**************************";
cout<<"Here is the full information of the document: "<<endl;
cout<<"\n\tCode :"<<ptr->code<<"\n \tTitle : "<<ptr->title<<"\n\tCreator : "<<ptr->creator;
cout<<"\n\tLocation :"<<ptr->location<<"\n \tFile Name : "<<ptr->filename<<"\n\tKeyword : "<<ptr->keyword;
cout<<"\n\tComment "<<ptr->comment;
cout<<endl<<"**************************";
break;
}
}
}
break;
.
.
.
.