Write a C Programm containing compress, de-compress logic

/**************************************************************/
/*Programmed by : Vivek Patel**********************************/
/*For Bugs Free feel to contact********************************/
/*Website : www.vivekpatel.cjb.net*****************************/
/*Email : vivek_patel9@rediffmail.com**************************/
/**************************************************************/

#include
#include
#include

void main(){
char string[50],tmp[50];
int spcnt[50],i,j,c;
clrscr();
printf("Enter a string : ");
gets(string);

//compress logic
for(i=0,c=0;string[i];i++){
if(string[i]==' '){
spcnt[c++]=i;
for(j=i;string[j];j++)
string[j]=string[j+1];
string[j]='\0';
}
}
spcnt[c]=-99;
textcolor(GREEN);
printf("\n");
cprintf("Compressed string is as follow : %s",string);

//decompressed logic
strcpy(tmp,"");
for(i=0,c=0;string[i];i++){
if(spcnt[c]==i){
tmp[i+c]=' ';
c++;
tmp[i+c]=string[i];
}
else{
tmp[i+c]=string[i];
}
}
tmp[i+c]='\0';
strcpy(string,tmp);
textcolor(RED);
printf("\n");
cprintf("De-Compressed string is as follow : %s",string);
getch();
}



Powered by Wufoo