anuraag dimri wrote:
> Hi there,
>  i tried sumtyn like decompressing a4b7c2 in to aaaabbbbbbbcc...didnt 
> worked... i'm storing it in an array of big size and then trying to first 
> shift b7c2 and then expand a4..is it acceptable.. heres the code...the 
> numbers i have assumed to be single digit numbers in the original string.
> 
> 
>   int main()
>   {
>   char s[100]="a4b6c8";
>   int i,j,k,l;
>   l=strlen(s);
>    
>   for(i=j=0; s[i]!='\0';i++)
>   {
>   if(s[i] >= 'a' && s[i] <= 'z')
>   s[j++]=s[i]; 
>    
>   if(s[i] >= '0' && s[i] <= '9')
>   {
>      k = s[i]-48;
>   while(i<l)
>   {
>      s[l+(k-2)]=s[l];
>       l--;
>   }
>       s[l+(k-1)]='\0'; /*marking the new end of string*/
>   }
>    
>   while((k-2)>0)
>   {/*some problem here may b*/
>      s[--j]=s[--i]; 
>      k--;
>   }
>   
>   }
>     s[j]='\0';
>   printf("\n%s",s);
>   }

Just so you know, pretty much every viable compression algorithm looks 
at the bitstream for patterns...usually of the repeating variety.  Your 
method is what is known as Run Length Encoding (RLE) but somewhat more 
basic.  RLE is generally considered to be a very weak compression 
algorithm.  PCX was the only widely used file format to use RLE (AFAIK).

Why are you bothering to even manipulate the string?  On many compilers, 
the code will "crash" (GPF) because you will be attempting to modify 
read-only memory.  Also, assuming you have enough memory for an 
operation on the stack involving strings is generally a bad idea. 
Calculate how much memory you need, allocate it, and then use the 
allocated space for the expanded data.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to