hi,
Im trying to write a function that decompresses a string and returns the original string.
for example:
p3B2c4 will be pppBBcccc
this is what I have tried to do, the function returns nothing.
pls tell me where I'm wrong.
Code:
char *uncompress(char *coded_string)
{
int size=0, i, j;
char *original = (char *)malloc(size*sizeof(char));
if (original == NULL)
{
printf("Dynamic allocation failed in uncompress\n");
return NULL;
}
for (i = 0; coded_string[i] != '\0'; i++)
{
if (coded_string[i] >=1)
size = size + coded_string[i] + 1;
}
for (j = 0; coded_string[j] != '\0'; j++)
{
if ((j % 2 )> 0)
{
original[j--] = coded_string[j];
}
}
free(original);
return original;
}