#include "stdafx.h"//work with txt files only
#include"iostream"
#include "fstream"
using namespace std;
void decompress(char* data, int count, FILE* outfile);
char* readFileData(char* filename, int* count_ptr);
struct compress
{
char runValue;
int counter;
compress(int x=0,int y=1):runValue(x),counter(y){}};
int _tmain(int argc, _TCHAR* argv[])
{
fstream infile1,infile2,outfile;
struct compress zip;
char cur;
char next;
char fName[100]="";
cout<<"please enter file name :";
cin>>fName;
infile1.open(fName,ios::in);
infile1.unsetf(ios::skipws);
infile2.open(fName,ios::in);
infile2.unsetf(ios::skipws);
outfile.open("compressed.txt",ios::out);
outfile.unsetf(ios::skipws);
while(1)
{
infile1>>cur;
if(infile1.fail()) break;
infile2>>next;
infile2>>next;
if(infile2.fail()) break;
while(1)
{
if(cur!=next)
{
outfile<<"1"<<cur; infile1>>cur;
infile2>>next;
if(infile2.fail()) break;
}
if(cur==next)
{
while(cur==next)
{
zip.counter++;
infile1>>cur;
infile2>>next;
if(infile2.fail()) break;
}
zip.runValue=cur;
outfile<<zip.counter<<zip.runValue;
zip.counter=1;
infile1>>cur;
infile2>>next;
if(infile2.fail()) break;
}
} } infile1.close();
infile2.close();
outfile.close();
cout<<"compression operion completed.\n";
return 0;
}
void decompress(char* data, int count, FILE* outfile)
{
for (int i = 0; i<count;> {
putc(data[i], outfile); }
}
char* readFileData(char* filename, int* count_ptr)
{
FILE* infile = fopen(filename, "rb.txt");
if (!infile)
{
printf("No such file \"%s\"!\n", filename);
exit(1);
}
fseek(infile, 0, SEEK_END);
int count = ftell(infile);
fseek(infile, 0, SEEK_SET);
char* data = new char[count];
fread(data, 1, count, infile);
fclose(infile);
*count_ptr = count;
return data;
}
this is the code and i need to decompress it