Skip to content

Commit

Permalink
Merge pull request tanus786#746 from SonuKushwaha-hub/patch-5
Browse files Browse the repository at this point in the history
Create Byte Stuffing
  • Loading branch information
tanus786 authored Oct 29, 2022
2 parents 03a8b3a + 50281a2 commit 80d2337
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Byte Stuffing
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <iostream>
using namespace std;

int main() {
char s[50], data[100];
int i,j,n,m;
cout<<"Enter Size"<<endl;
cin>>n;
cout<<"Enter Data"<<endl;
for(int i=0;i<n;i++)
cin>>s[i];

data[0] = 'D';
data[1] = 'L';
data[2] = 'E';
data[3] = 'S';
data[4] = 'T';
data[5] = 'X'; j = 6;
m = 6;

for(int i=0;i<n;i++) {
if(s[i]=='D' && s[i+1]=='L' && s[i+2]=='E') {
data[j++] = 'D'; data[j++] = 'L';
data[j++] = 'E';
data[j++] = 'D';
data[j++] = 'L';
data[j++] = 'E';
i+=2;
m+=6;
} else {
data[j++]=s[i];
m++;
}
}
data[m++] = 'D';
data[m++] = 'L';
data[m++] = 'E';
data[m++] = 'E';
data[m++] = 'T';
data[m++] = 'X';
cout<<endl;

for(int i = 0;i<m;i++)
cout<<data[i]<<" ";

return 0;
}

0 comments on commit 80d2337

Please sign in to comment.