Character Stuffing with c++
a serious problem occurs when binary data itself will contain flag bytes bit pattern . this situation usually interfere with the framing . one solution is character or byte stuffing where senders data link layer insert a special escape byte just before each "accidental" flag byte in the data . at the receiving end data link layer remove the escape byte before the data are given to the network layer .
implementation :
#include<bits/stdc++.h>
using namespace std;
int main()
{
char so[100],data[100];
cout<<"Enter the text: ";
cin>>so;
char flag,bit;
cout<<"enter the flag: ";
cin>>flag;
cout<<"enter the character: ";
cin>>bit;
//scanf("%c %c",&flag,&bit);
int size=strlen(so);
//char data[2*size+3];
data[0]=flag;
int i,j;
for(i=0,j=1;i<size;i++)
{
if(so[i]==bit)
{
data[j]=so[i];
j++;
data[j]='k';
j++;
}
else{
data[j]=so[i];
j++;
}
}
data[j]=flag;
data[j+1]='\0';
cout<<data;
return 0;
}
Output:
Character Stuffing with c++
Reviewed by Saroar Zahan Sojib
on
February 22, 2019
Rating:
No comments: