#include <stdio.h>
#include <dos.h>
#include <conio.h>
/* File compression - Huffman code */
/* Bil Stefanidis */
void insert(int, int);
void swap(int *, int, int);
void bin(int,int);
int removee(void);
int aa[42] ;
int p[42], info[42];
int N,L;
FILE *fpi, *fpo;
void main(void){
char a[500];
int val[240] , j ,l,x;
int count[44], count2[44],code[44],len[44];
char i ;
int t,k,t1,t2,flag,cout;
int dad[44];
clrscr();
N=0;
for (i=0;i<=43;i++){
code[i]=0;
count[i]=0;
len[i]=0;
dad[i]=0;
aa[i]=0;
}
i=0;
fpi=fopen("input.txt" , "r");
if (fpi==NULL) { printf("The file dont exist\n");}
for(j=0;j<=201;j++){
a[j]='';
}
for(j=0;j<=130;j++){
val[j]=0;
}
j=0;
while ( !feof(fpi) ) {
fscanf(fpi,"%c",&i);
printf("%c",i);
a[j]=i;
j=j+1;
}
printf("\n\n");
for(j=0;j<=200;j++){
printf("%c",a[j]);
}
getch();
getch();
/* Edw metrame poses fores emfanizetai
kathe character se ascII morfh */
for (j=0;j<=200;j++){
printf("a[j]=%d , val[a[j]]=%d \n",a[j],val[a[j]]);
val[a[j]]++;
}
/* Edw arxikopoioume enan counter */
for(j=0;j<=26;j++){
count[j]=0;
}
/* Edw topothetoume tiw metrhseis se enan
counter */
count[0]=val[32];
printf("Oi syxnothtes twn xarakthrwn symfwna me to ASCII
tous\n");
for(j=97;j<=121;j++){
if (val[j]!=0) {
count[j-96]=val[j];
}
printf(" val[%c]=%d \n",j,val[j]);
getch();
}
/* parousiazoume ta apotelesmata gia tous
26 xarakthres */
printf("Oi syxnothtes twn 26 xarakthrwn tou
alfabhtou\n");
for(j=1;j<=26;j++){
printf(" count[%d]=%d \n",j,count[j]);
getch();
}
/* parousiazoume th syxnothta emfanishs tou
space */
printf(" sp is appear ");
for (l=0;l<val[32];l++){
printf("%c",'*');
}
/* ------------------ */
/* parousiazoume th suxnothta emfanishs twn
allwn xarakthrwn */
printf(" %d times , count[%d]=%d\n",l,0,count[0]);
for (j=97;j<=121;j++){
printf(" %c is appear ",j);
for (l=0;l<val[j];l++){
printf("%c",'*');
}
printf(" %d times ,
count[%d]=%d\n",l,j-96,count[j-96]);
getch();
}
/* ------------------ */
fclose(fpi);
l=0;
printf("To count2 periexei th syxnothta emfanishs mono
twn\n");
printf("xarakthrwn pou yparxoun sto keimeno\n");
for (j=0;j<=26;j++){
if (count[j]!=0) {
count2[l]=count[j];
printf("count2[%d]=%d \n",l,count2[l]);
l++;
}
}
getch();
getch();
/* The finish of character counting */
for (i = 0; i <= 26; i++)
if (count[i]){
insert(count[i],i);
}