#include<conio.h>
#include<iostream,h>
#include<string.h>
#include <stdio.h>
#include <stdlib.h>
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;
//cout<< select;
output = select + 64;
cout << char(output);
}
void decode()
{
cout<<"\nEnter the data stream ";//<<endl;
cin >> input_stream;
length_of_stream = strlen(input_stream);
//cout<< length_of_stream ; //only for debugging
/********************************************
the code starts here...
********************************************/
count = length_of_stream;
//count -= count;
for(int ini =0; ini<=count ; ini++)
{
for(int final=1;final<count;final++)
{
strncpy(cut_stream, &input_stream[ini], final);
//cut_start = cut_start + 1;
cout << final;
/*********************************************
compare
*********************************************/
temp_num = atoi(cut_stream);
for(int z= 1;z<=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<< "im in test";
break;
}
}
}
cout<< "end";
while(1);
}
//cout<< decoded_stream;
//while(1);
void main()
{
cut_start =0;
cut_end = 1;
cout << "Huffman decoder" << endl;
cout << "Enter the codes for a-z" << endl;
for(int i =1;i<=3;i++)
{
cin >> codes[i];
}
decode();
}