-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDECOMPr.C
More file actions
87 lines (80 loc) · 1.47 KB
/
DECOMPr.C
File metadata and controls
87 lines (80 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<string.h>
struct File_Info
{
int Min_BitSize;
char *FName;
long FSize;
}Fhead;
int Min_BitSize;
struct table
{
unsigned char ch;
long int count;
int nbits;
unsigned int bvalue;
} Thead[255];
FILE *Fp,*Fp1;
void Decompress(unsigned char);
void main()
{
unsigned char c;
clrscr();
if((Fp=fopen("Write.txt","r"))==NULL)
{
printf("Error in file open");
exit(0);
}
if((Fp1=fopen("File1.txt","w"))==NULL)
{
printf("Error in file open");
exit(0);
}
fread(&Fhead,sizeof(Fhead),1,Fp);
fread(&Thead,sizeof(Thead),1,Fp);
while((c=fgetc(Fp))!=EOF)
Decompress(c);
fcloseall();
}
void Decompress(unsigned char Dstr)
{
int Compval,i,k;
static unsigned char Rchar='\0',Rchar1='\0';
int flag;
static long count=0;
static int j;
Compval=128;
for(k=0;k<8;k++)
{
if (k==0) Rchar=Rchar1<<1;
Rchar |=(Dstr & Compval) ? 1:0;
Compval >>=1;
j++;
if (j>=Min_BitSize)
{
Rchar1=Rchar;
Rchar <<=(8-j);
for(i=0;i<255;i++)
{
if(j==Thead[i].nbits && Rchar== Thead[i].bvalue)
{
if (count >= Fhead.FSize) exit(0);
printf("%c", Thead[i].ch);
fputc(Thead[i].ch,Fp1);
Rchar='\0'; flag=1;
count++;
j=0;
break;
}
}
if(flag==1)
Rchar >>=(8-j);
else
Rchar=Rchar1;
}
Rchar<<=1;
}
Rchar1=Rchar>>1;
}