-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbit_stuff_destuffing.cpp
More file actions
85 lines (83 loc) · 1.83 KB
/
Copy pathbit_stuff_destuffing.cpp
File metadata and controls
85 lines (83 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*@athour....
Name: Md.Manzurul Alam
Dept. of CSE, GUB
ID:202902003
CSE 308 || Data Communication
*/
#include <iostream>
#include <string>
#define MAXSIZE 100
using namespace std;
int main()
{
char *p, *q;
char temp;
char in[MAXSIZE];
char stuff[MAXSIZE];
char destuff[MAXSIZE];
int count(0);
cout << "Enter input string(0's & 1's only):" << endl;
cin >> in;
//stuffing on sender's site...........................................
cout << "\n ---- After BitStuffing ----" << endl;
p = in;
q = stuff;
while (*p != '\0')
{
if (*p == '0')
{
*q = *p;
q++;
p++;
}
else
{
while (*p == '1' && count != 5)
{
count++;
*q = *p;
q++;
p++;
}
if (count == 5)
{
*q = '0';
q++;
}
count = 0;
}
}
*q = '\0';
cout << "\n BitStuffed character string : " << stuff << endl;
//destuffing on reciever's site..................................................
cout << "\n ============== After BitDeStuffing ===============" << endl;
p = stuff;
q = destuff;
while (*p == '\0')
{
if (*p == '0')
{
*q = *p;
q++;
p++;
}
else
{
while (*p == '1' && count != 5)
{
count++;
*q = *p;
q++;
p++;
}
if (count == 5)
{
p++;
}
count++;
}
}
*q = '\0';
cout << "\n BitDeStuffed character string :";
cout << in;
}