M
Maxx
Ok here is this program to compress a given file using run-length
encoding. This technique reduces the size of the file by replacing the
original bytes with the repetition count and the byte to be repeated.
Ex: if the file to be compressed starts with the following sequence of
bytes::
46 6F 6F 6F 2B 2B 9C 81 81 81 81 84 84 84 7A 7A 7A
The compressed file will contain the following bytes::
01 46 03 6F 02 2B 01 9C 04 81 03 84 03 7A
And the output file will have a .rle extension along with the original
file name that was provided when the program was run. here is the
program i wrote:::
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXBUFF 5000
int main(int argc, char *argv[])
{
FILE *fp,*gp;
int ch, a[MAXBUFF],o[MAXBUFF],n=0,i,k;
int *p=a,*r=a,*q=o;
if(argc ==1)
{
fprintf(stderr,"Too few arguments");
exit(1);
}
if(fp=fopen(*++argv,"rb")==NULL)
{
fprintf(stderr,"Can't open file",*argv);
exit(2);
}
if(gp=fopen(*argv[1]+".rle","wb")==NULL)
{
fprintf(stderr,"Can't open file");
exit(2);
}
while(fscanf(fp,"%.2X",&ch)==1)
{
*p++=ch;
++n;
}*p='\0';
for(i=0;i<n;i++)
{
int j=*(r+i),m=0;
for(k=0;k<n;k++)
{
if(j==*(r+k))
{
++m;
}
}
*q++=m;
*q++=j;
}*q='\0';
while(*q!='\0')
{
putc(*q,gp);
q++;
}
}
It got compiled well but when i run it it gives me the following
error::"The instruction at "0x004010b4" referenced memory at
"0x00000000". The memory could not be read."
Please help, i can't seem to figure it out
encoding. This technique reduces the size of the file by replacing the
original bytes with the repetition count and the byte to be repeated.
Ex: if the file to be compressed starts with the following sequence of
bytes::
46 6F 6F 6F 2B 2B 9C 81 81 81 81 84 84 84 7A 7A 7A
The compressed file will contain the following bytes::
01 46 03 6F 02 2B 01 9C 04 81 03 84 03 7A
And the output file will have a .rle extension along with the original
file name that was provided when the program was run. here is the
program i wrote:::
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXBUFF 5000
int main(int argc, char *argv[])
{
FILE *fp,*gp;
int ch, a[MAXBUFF],o[MAXBUFF],n=0,i,k;
int *p=a,*r=a,*q=o;
if(argc ==1)
{
fprintf(stderr,"Too few arguments");
exit(1);
}
if(fp=fopen(*++argv,"rb")==NULL)
{
fprintf(stderr,"Can't open file",*argv);
exit(2);
}
if(gp=fopen(*argv[1]+".rle","wb")==NULL)
{
fprintf(stderr,"Can't open file");
exit(2);
}
while(fscanf(fp,"%.2X",&ch)==1)
{
*p++=ch;
++n;
}*p='\0';
for(i=0;i<n;i++)
{
int j=*(r+i),m=0;
for(k=0;k<n;k++)
{
if(j==*(r+k))
{
++m;
}
}
*q++=m;
*q++=j;
}*q='\0';
while(*q!='\0')
{
putc(*q,gp);
q++;
}
}
It got compiled well but when i run it it gives me the following
error::"The instruction at "0x004010b4" referenced memory at
"0x00000000". The memory could not be read."
Please help, i can't seem to figure it out