Text compression in c program | computer graphics lab

Friday, May 28, 2010

Text compression is mainly used for reduce the file size. Text compression process Encoding information’s using fewer bits than an unencoded representation.

#include”stdio.h”
#include”conio.h”
#include”string.h”
int count=0,i,j,flag=0;
char n1[20],n2[20],ch,chh,a=':';
FILE *f1,*f2;
void enc()
{
while(!feof(f1))
{
fscanf(f1,"%s",n1);
for(i=0;i<=strlen(n1);i++)
{
ch=n1[i];
chh=n1[i+1];
if(ch==chh)
count++;
else
{
count++;
fprintf(f2,"%c%d",ch,count);
printf("%c%d",ch,count);
getch();
count=0;
}
}
fprintf(f2,"%c",a);
printf("%c",a);
}
fclose(f1);
fclose(f2);
}
void dec()
{
FILE *f;
f=fopen("o.txt","r");
while(!feof(f))
{
fscanf(f,"%c %d",&ch;,&count;);
if(ch==':')
{
printf("\n");
continue;
}
for(i=0;i
printf("%c",ch);
}
}
void main()
{
f1=fopen("bb.txt","r");
f2=fopen("o.txt","w");
clrscr();
puts("Uncompressed File\n");
enc();
puts("\nDecompressed File\n");
dec();
getch();
}

OUTPUT
INPUT FILE:

bb.txt:
o.txt:
U1d1h1a1y1a1
OUTPUT:
Uncompressed File

0 comments:

Post a Comment