Note that there are some explanatory texts on larger screens.

plurals
  1. POhuffman decoding is going nutts
    text
    copied!<p>The problem is that I can decode a data stream for the first time, but then it will become an infinite loop and display the same value over and over again... I'm using borland C++. Decoding is done by first saving the text a to z in an array, then taking the input data stream and then cutting the contents of the array using strcpy then comparing with the contents of the first array then if a match is found, the corresponding ASCII is printed. </p> <p>code:</p> <pre><code>#include&lt;conio.h&gt; #include&lt;iostream.h&gt; #include&lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; using namespace std; int codes[512]; char cut_stream[100]; char input_stream[100]; char decoded_stream[256]; int test,count,cut_start,cut_end,length_of_stream,final,temp_loop_s,temp_loop_e,temp_num,comp_num,send; void select_num(int select) { int output; output = select + 64; cout &lt;&lt; char(output); } void decode() { cout&lt;&lt;"\nEnter the data stream ";//&lt;&lt;endl; cin &gt;&gt; input_stream; length_of_stream = strlen(input_stream); //cout&lt;&lt; length_of_stream ; //only for debugging /******************************************** the code starts here... ********************************************/ count = length_of_stream; //count -= count; for(int ini =0; ini&lt;=count ; ini++) { for( final=1;final&lt;=count;final++) { strncpy(cut_stream, &amp;input_stream[ini], final); //cut_start = cut_start + 1; /********************************************* compare *********************************************/ temp_num = atoi(cut_stream); for(int z= 1;z&lt;=26;z++) { comp_num = codes[z]; if(comp_num == temp_num) { send =z; select_num(send); test =1; comp_num =0; break; } } if( test ==1) { test =0; ini = final-1; // the increment will be given on the next for loop so it is reduced here //final =0; //cout&lt;&lt; "im in test"; break; } } } cout&lt;&lt; "end"; while(1); } //cout&lt;&lt; decoded_stream; //while(1); void main() { cut_start =0; cut_end = 1; cout &lt;&lt; "Huffman decoder" &lt;&lt; endl; cout &lt;&lt; "Enter the codes for a-z" &lt;&lt; endl; for(int i =1;i&lt;=3;i++) { cin &gt;&gt; codes[i]; } decode(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload