Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
40 views3 pages

Ex-2 CN Lab

The document outlines an experiment to implement data link layer framing methods, specifically character stuffing and bit stuffing. It includes C programs for both methods, demonstrating how to handle delimiters and binary data. The output examples illustrate the results of the stuffing processes for given inputs.

Uploaded by

schaitanya304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Ex-2 CN Lab

The document outlines an experiment to implement data link layer framing methods, specifically character stuffing and bit stuffing. It includes C programs for both methods, demonstrating how to handle delimiters and binary data. The output examples illustrate the results of the stuffing processes for given inputs.

Uploaded by

schaitanya304
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT-2

2. AIM: Write a Program to implement the data link layer farming methods such as
i) Character stuffing ii) bit stuffing.
i) Character Stuffing
Program:
#include<stdio.h>
#include<string.h>
void main()
{
char a[30], fs[50] = " ", t[3], sd, ed, x[3], s[3], d[3], y[3];
int i, j, p = 0, q = 0;
clrscr();
printf("Enter characters to be stuffed:");
scanf("%s", a);
printf("\n Enter a character that represents starting delimiter:");
scanf(" %c", &sd);
printf("\nEnter a character that represents ending delimiter:");
scanf(" %c", &ed);
x[0] = s[0] = s[1] = sd;
x[1] = s[2] = '\0';
y[0] = d[0] = d[1] = ed;
d[2] = y[1] = '\0';
strcat(fs, x);
for(i = 0; i<strlen(a); i++)
{
t[0] = a[i];
t[1] = '\0';
if(t[0] == sd)
strcat(fs, s);
else if(t[0] == ed)
strcat(fs, d);
else
strcat(fs, t);
}
strcat(fs, y);
printf("\n After stuffing:%s", fs);
}
Output:
Enter characters to be stuffed: goodday
Enter a character that represents starting delimiter: d
Enter a character that represents ending delimiter: g
After stuffing: dggooddddayg.
ii) Bit stuffing
Program:
#include<stdio.h>
#include<string.h>
int main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size:");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
return 0;
}
Output for Bit stuffing:
Enter frame size:12
Enter the frame in the form of 0 and 1 : 0 1 0 1 1 1 1 1 1 0 0 1
After Bit Stuffing : 0101111101001

You might also like