#include <stdio.h> #include <conio.h> #include <string.h> 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(); }