I want to initialize an array of pointers. This is my code. It works fine for smaller numbers i.e 9979, but when I try to initialize dynamically to 66071, it shows segmentation fault. Now I had in another program, initialized dynamically an array of integers to a size of 120007, which worked fine, i.e. no segmentation faults. Any idea why this error is happening for array of pointers? Could it be due to the structure size of "dictnode"?
struct dictnode{
string word;
int key;
int code;
};
class LZW{
dictnode **de_table;
int count_dec;
int desize;
public:
LZW();
//DECOMPRESSION
void decompress();
void storedictdec(string str1, string str2);
void storedictdec1(string str1, string str2, int dec);
bool checkdictdec(int n);
void initialize_dec_dict();
void printdictdec();
int quadprobe(int k, int i);
};
LZW::LZW(){
desize=66071;
count_dec=0;
de_table = new dictnode* [desize];
for(int i=0; i<desize; i++){
de_table[i]=NULL;
}
return;
}
de_table?std::vectorfor the dynamic array? Additionally you probably want to use the initalizer list for your class en.cppreference.com/w/cpp/language/initializer_list