answersLogoWhite

0


Best Answer

{

unsigned char **dict;

int *dlength;

unsigned char p[80], temp[80];

char c;

int plength,i,j,k,diff,cd;

plength=1;

cd=256;

p[0]=EOF;

dict= (unsigned char *)malloc(99999); //Allocating memory for Dictionary

if(dict == NULL)

printf("Unable to allocate memory \n");

dlength=(int *)malloc(99999);

for (i = 0; i < 99999; i++) {

dict[i]=(unsigned char *)malloc(60);

if(dict[i]==NULL)

printf("Unable to allocate memory \n");

}

for (i=0;i<256;i++) //loading dictionary with ASCII set

{

dict[i][0]=i;

dlength[i]=1;

}

while ((c = fgetc(Fpt)) != EOF)

{

if(cd==256)

p[0]=(unsigned char *)c;

diff=0;

for (i=0; i<cd; i++)

{

for (k=0; k<plength; k++) //checking to see if p+c in dict

{

if(dict[i][k]!=p[k])

diff=1;

}

}

if (diff==0)

{

p[plength]=(unsigned char)c;

plength++;

}

if (diff==1)

{

for (i=0; i<cd; i++)

{

for (k=0; k<plength; k++)

{

if(dict[i][k]!=p[k])

diff=1;

}

if (diff==0)

j=i;

}

fputc(j, outfile);

for (i=0; i<plength; i++)

{

dict[cd][i]= p[i];

}

dict[cd][plength]=(unsigned char)c;

cd++;

p[0]=c;

}

}

for (i=0; i<cd; i++)

{

for (k=0; k<plength; k++)

{

if(dict[i][k]!=p[k])

diff=1;

}

if (diff==0)

j=i;

}

fputc(j, outfile);

fclose(outfile);

fclose(Fpt);

}

By Amit Setia

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Implementation of LZW compression algorithm in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Where do you get the exact source code in C that implements lossless compression algorithm?

The source code, in C, will depend on what type of lossless compression algorithm will be used. A source code should be available from various computer scientists in your area.


What is GCD in C Plus Plus?

A C++ implementation of the Binary GCD (Stern's) algorithm is shown in the Related Link below.


How you write C plus plus programming code for Lempel-Zip and Walch algorithm to compress files?

Lempel-Ziv-Welch (LZW) encoding is patented, thus we cannot show you a working example. However, the basic algorithm is well-documented on various websites including Wikipedia. If you can follow the algorithm, you can write the code. But you cannot distribute the code without the requisite licence.


Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.


How can you implement Ricart and Agrawala's algorithm in c?

Ronaldo! 'c' coding of Ricart-agarwala algorithm


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.


What is algorithm in c?

Algorithm is a step by step process to solve a particular task.


What is an algorithm for multiplying rational numbers?

The algorithm is A/B * C/D = AB/CD.


C code to implement the file allocation algorithm?

yes we can do it,in c


Can you give a C program about SJF algorithm?

no.


Program in c to develop an algorithm that prints the n value of algorithm?

reymond rillera reymond rillera


Why the source coding of every compression utility software is in Visual C plus plus and why not in java?

Compression/decompression is all about raw speed and efficiency. Java is neither fast nor efficient. However, converting from C++ to Java isn't terribly difficult and Huffman's algorithm and its variations are well documented. Just don't expect to create anything that's remotely useful to you in Java.