Bit Stuffing and Destuffing
C language code: -
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *p,*q;
char temp;
char in[100];
char stuff[100];
char destuff[100];
int count=0;
printf("enter the input character string (0‘s & 1‘s only):\n");
scanf("%s",in);
p=in;
q=stuff;
while(*p!='\0')
{
if(*p=='0')
{
while(*p=='0' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='1';
q++;
}
count=0;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
*q='0';
q++;
}
count=0;
}
}
*q='\0';
printf("\nafter bit stuffing is:");
printf("\n%s",stuff);
p=stuff;
q=destuff;
while(*p!='\0')
{
if(*p=='0')
{
while(*p=='0' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
else
{
while(*p=='1' && count!=5)
{
count++;
*q=*p;
q++;
p++;
}
if(count==5)
{
p++;
}
count=0;
}
}
*q='\0';
printf("\nAfter bit destuffing is:");
printf("\n%s\n",destuff);
return 0;
}