Program received signal SIGSEGV, Segmentation fault.
0x0000000000402580 in writeBit (f=0x0, b=0) at binary1.cpp:26
26 putc(b + '0', f->file);
Information:
writeBit function is as follows:
/***********************************************
* writeBit *
***********************************************
* Write bit b into open file f. b must be *
* 0 or 1. *
***********************************************/
void writeBit(BFILE* f, int b)
{
putc(b + '0', f->file);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
I only use writeBit 3 times.
HERE
//writeCode(f, str) writes string str to BFILE* f, one bit
//at a time.
void writeCode(BFILE* f, string str)
{
int y = str.length();
for(int x = 0; x < y; x++)
{
writeBit(f, str[x]-'0');
}
}
AND HERE
void writeTree(BFILE* f, Node* t)
{
if(t->kind!=leaf)
{
writeBit(f, 0);
writeTree(f, t->left);
writeTree(f, t->right);
}
else
{
writeBit(f, 1);
writeByte(f, t->ch);
}
}