Hi all,
I got this assertion problem that i cant seem to solve, could you guys help me on this. So far, i think the problem might be due to the while loop for the iterator line by line check and i have made changes to it but still cant solve it.
Debug assertion failed
file:f\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c
Line: 1317
Expression: _CrtIsValidHeappointer(pUserData)
file:f\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c
Line: 1419
Expression: _pFirstBlock == pHead
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
ifstream ckin("sample.txt");
int initclock = 0;
if (ckin==NULL)
{
MessageBox::Show ("not found");
ckin.close();
initclock++;
}
if (ckin!=NULL)
{
char checkEmpty;
ckin.get(checkEmpty);
if (!ckin.eof())
{textBox1->Text = "file empty";
ckin.close();
}
else
{textBox1->Text = "not empty";
ckin.close();
initclock++;
}
}
ifstream in("sample.txt");
string line;
string match("sample\:");
int clock = 0 ;
while (getline(in, line)&&(initclock==0))
{
stringstream sstrm(line);
string::iterator iter =
search (line.begin(),line.end(),match.begin(),match.end());
if (iter != line.end() )
{
iter = find_if( iter +match.length(), line.end(),not1(ptr_fun <int,int> (isspace)));
if (iter == line.end())
{
MessageBox::Show ("No numbers or words after Serial no. :");
break;
}
string::iterator j = find_if (iter, line.end(), ptr_fun <int,int> (isspace));
string found;
copy(iter, j, back_insert_iterator <string> (found));
//create a new file based on the word after said word
//and saved it into the said folder
string filename = found + ".txt";
string dirname = "log//";
string finaldir = dirname + filename;
ofstream(finaldir.c_str());
//using ifstream and ofstream to copy content of file to another
char * fbuffer;
long fsize;
ifstream cpy ("sample.txt",ios::binary);
ofstream target (finaldir.c_str(),ios::binary);
cpy.seekg(0,ifstream::end);
fsize=cpy.tellg();
cpy.seekg(0);
fbuffer = new char [fsize];
cpy.read (fbuffer,fsize);
target.write (fbuffer,fsize);
delete[] fbuffer;
cpy.close();
target.close();
//write the found word/serial no. into temp.txt
const char * buffer=found.c_str();
string str (found.c_str());
int sizeNum = str.length();
long size = sizeNum;
ofstream outfile ("store.txt");
outfile.write (buffer,size);
//delete[] buffer;//release dynamically allocated memory
outfile.close ();
//textbox update and check if previous saved name is the same as
//current one
textBox2->Text = System::IO::File::ReadAllText("store.txt");
if (textBox2->Text == label3->Text) {
MessageBox::Show ("no. repeated");
}
else
{
label3->Text = textBox2->Text;
}
//try to use an empty file to write and empty a file
//which is being used by another program
char * ebuffer;
long esize;
ifstream ecpy ("void.txt",ios::binary);
ofstream etarget ("sample.txt",ios::binary);
ecpy.seekg(0,ifstream::end);
esize=ecpy.tellg();
ecpy.seekg(0);
ebuffer = new char [esize];
ecpy.read (ebuffer,esize);
etarget.write (ebuffer,esize);
delete[] ebuffer;
ecpy.close();
etarget.close();
textBox1->Text = "done";
clock++;
in.close();
if (clock!=0)
break;
}//if iter
else
{
textBox1->Text = "not found";
}
}//while
}