Professional Documents
Culture Documents
Character Stuffing: Kush Dept. of Cse
Character Stuffing: Kush Dept. of Cse
Character Stuffing: Kush Dept. of Cse
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.
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