You are on page 1of 2

/Program to implement Bit Stuffing

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *message,*snd_message,*header;
int no_of_1_h=0,i,j=0,count_1=0;
clrscr();
printf("\n\t enter the message : ");
gets(message);
printf("\t enter the header : ");
gets(header);
printf("\t sending message is : \n\n\t ");
/* Procedure to find the total no's of 1 in header */
for(i=0;i<strlen(header);i++)
{
if(header[i]=='1')
no_of_1_h++;
}
/* Initialisation of local variable */
i=0;
/* procedure to find the sending message */
while(*message)
{
snd_message[i]=message[j];
/* condition for chacking the no's of 1 in input message */
if(message[j]=='1')
count_1++;
else
count_1=0;
i++;
if(count_1==no_of_1_h)
{
snd_message[i-1]='0';
count_1=0;
j--;
}
j++;
if(message[j]=='\0')
break;
}
snd_message[i]='\0';
printf("%s %s %s",header,snd_message,header);
getch();
}
/*OUTPUT
enter the message : 110111111111110110
enter the header : 0111111
sending message is :
0111111 11011111011111010110 0111111

You might also like