Text Compression CS1355 Graphics and Multimedia Lap

Text Compression program using fopen function it will open the particular file from the source. In the first file it will read the file then in the output file using w option it will perform the write option into the file. using these text compression it will reduce the size of the file
Source code Text compression in C language programming
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0,j=0,count=0;
char ch, str[32000];
FILE *f1,*f2;
clrscr();
f1=fopen("D:\INPUT.TXT","r");
while((str[i]=getc(f1))!=EOF)
{
printf("%c",str[i]);
i++;
}
getch();
printf("\n");
f2=fopen("D:\OUTPUT.TXT","w");
fclose(f2);
while(j<=i)
{
ch=str[j];
while(ch==str[j]&&j<=i)
{
count++;
j++;
}
f2=fopen("D:\OUTPUT.TXT","a");
printf("\n%c%d",ch,count);
fprintf(f2,"%c%d",ch,count);
fclose(f2);
count=0;
j++;
}
fclose(f1);
getch();
}

Related post