Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***C++**** int main(int argc,char *argv[]) { string filename; const string END_O

ID: 3918047 • Letter: #

Question

***C++****

int main(int argc,char *argv[]) {

string filename;

const string END_OF_BOOK_DATA = "***************";

string title, body, line;

filename=argv[1];

  

ifstream infile(filename.c_str());

if(infile.fail()){

cout << "ERROR: could not open input file " << filename << endl;

return 1;

}

// HashTable blist;

ZippedBookNode *here=new ZippedBookNode;

Utils *here2;

int i=0;

HashTable<4> myHashTable;

while(getline(infile, title)){

title = title.substr(1);

body = "";

while(getline(infile, line)){

if(line == END_OF_BOOK_DATA)

break;

body += line + " ";

}

string encodedString;

here2->computeFrequency(body, body.length());

here2->HuffmanCodes(body.length());

for (auto i: body) encodedString+=codes[i];

//here2->decode_file(minHeap.top(), encodedString);

here[i].title=title;

here[i].c_excerpt=encodedString;

here[i].huff_root=minHeap.top();

here[i].next=NULL;

//cout<<encodedString<<endl;

cout<<here[i].title<<endl;

i++;

cout<<i<<endl;

// myHashTable.insertNode(here);

}

cout<<i<<endl;

infile.close();

for(int i=0;i<4;i++){

cout<<here[i].title<<endl;

}

myHashTable.insertNode(here);

// myHashTable.printTitles();

cout<<"!"<<endl;

return 0;

  

}

*************************************************************************************************************

As you see the part :::

here[i].title=title;

here[i].c_excerpt=encodedString;

here[i].huff_root=minHeap.top();

here[i].next=NULL;

I am unble to add data on here node. It only loops like once and all I can save is data for i=0; but I can't move fuether. Can you help me out???

Can you go through this code?

Explanation / Answer

As regards your problem, you have actually not placed the 'here' node part inside a loop. Since you've not used braces, your loop will execute just one line, and in this case, that line is
encodedString+=codes[i];
Also, if you want to make a linked list using here node, you need to make a temp node with no data and do:

here.next = temp;

here = here.next;
The temp node will have NULL data, but a valid address, and in the next iteration, the required node will get new data. The check condition for the end of the linked list developed in this way will be if(temp.data==NULL).
Also, to store the linked list for future use during your program, save the head of the list beforehand.