Character Stuffing: Kush Dept. of Cse

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

KUSH

DEPT. OF CSE
Date:
Exp No: 2

CHARACTER STUFFING
AIM: Program to implement the data link layer methods such as
character stuffing.
DESCRIPTION:
The second framing gets around the problem of resynchronization
after an error by having each frame start with the ASCII character with
the sequence DLESTX and end with sequence. In the way if the
destination even losses the track of frame boundaries. All it has to do is
look for DLESTX or DLEETX character to figure out when it is a serious
problem occurred with method.

When binary data such a object

programs or floating point numbers are being transmitted.


Each accidental DLE character in the data link layer on the
receiving at remaining the DLE before the data are given to the network
layer. This is called character stuffing. Thus a framing DLESTX OR
DLEETX can be distinguish from one in the data by the absence or
presence of a single DLE.A major disadvantage of using this framing
method is that closely tied to character.
ALGORITHM:
Step 1: start
Step 2: read the characters
Step 3: place DLE STX and DLEETX
Step 4: if (n+6) then go to step 8
Step 5: if (a[I]=d && a[I+1]=l && a[I+2]=e)
Step 6: right shift from position I by 3 characters
Step 7: go to step 4
6

KUSH
DEPT. OF CSE
Date:
Exp No: 2
Step 8: print the stuffed characters
Step 9: if(I>(n+6)) then go to step 13
Step 10: if (a[I]=d && a[I+1]=l && a[I+2]=e)
Step 11: left shift up to i by 3 characters
Step 12: go to step 9
Step 13: left shift by 6 characters
Step 14: print the destuffed characters
Step 15: stop

PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
char s[100],a[100];
int i,j,k,n,ch,l;
clrscr();
while(1)
{
printf("\nmenu\n");
printf("1.stufing\n2.destuffing\n3.exit");
printf("enter ur choice");
scanf("%d",&ch);
switch(ch)
{

KUSH
DEPT. OF CSE
Date:
Exp No: 2
case 1:
j=0;k=0;
a[j++]='D';
a[j++]='L';
a[j++]='E';
a[j++]='S';
a[j++]='T';
a[j++]='X';
printf("\n enter string");
scanf("%s",&s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]=='D'&&s[i++]=='L'&&s[i+2]=='E')
{
a[j++]='D';
a[j++]='L';
a[j++]='E';
a[j++]=s[i];
a[j++]=s[i+1];
a[j++]=s[i+2];
i=i+2;

KUSH
DEPT. OF CSE
Date:
Exp No: 2
k=k+3;
}
else
a[j++]=s[i];}
a[j++]='E';
a[j++]='T';
a[j++]='X';
a[j++]='D';
a[j++]='L';
a[j++]='E';
a[j++]='\0';
for(i=0;i<j;i++)
{
printf("%2c",a[i]);
}
break;
case 2:
i=0;j=0;k=0;l=0;
printf("enter stufed string:");
scanf("%s",&s);
l=strlen(s);
for(i=6;i<l-6;i++)

KUSH
DEPT. OF CSE
Date:
Exp No: 2
{
if(s[i]=='D'&&s[i+1]=='L'&&s[i+2]=='E')
{
a[j++]=s[i];
a[j++]=s[i+1];
k=k+3;
i=i+5;
}
else
a[j++]=s[i];
}
a[j]='/0';
for(i=0;i<j;i++)
{
printf("%2c",a[i]);
}
break;
case 3:exit(0);
default:printf("n");
}
}
}

10

KUSH
DEPT. OF CSE
Date:
Exp No: 2

11

You might also like