You are on page 1of 10

Computer Networks

KITS ENGG COLLEGE Page No:



AIM:- Implement the data link layer framing methods such as Character Stuffing.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0;j=0;n,pos;
char a[20],a[50],ch;
clrscr();
printf(enter string :);
scanf(%s,&a);
n=strlen[a];
printf(enter position:);
scanf(%d,&pos);
if(pos>n)
{
printf(invalid position,enter again);
scanf(%d,&pos);
}
printf(enter the character);
ch=getche()
b*0+=d;
b[1+=l;
Computer Networks

KITS ENGG COLLEGE Page No:

b*2+=e;
b*3+=s;
b*4+=t;
b*5+=x;
j=6;
while(i<n)
{
if I = = position-1
{
b*j+=d;
b*j+1+=l;
b*j=2+=e;
b*j+3+=ch;
b*j+4+=d;
b*j+5+=l;
b*j+6+=e;
then
j=j+7;
}
If a[j]=d;
b[j+1]=l;
b[j+2]=e;
j=j+3;
}
Computer Networks

KITS ENGG COLLEGE Page No:

b[j]=a[i];
I++;
J++;
}
b[j]=d;
b*j+1+=l;
b*j+2+=e;
b*j+3+=e;
b*j+4+=t;
b*j+5+=x;
b[j+6]= \0;
printf(frame after stuffing is:);
printf(%s,b);
getch();
}









Computer Networks

KITS ENGG COLLEGE Page No:


Input:
Enter string : a s d l e f g h
Enter position: 8
invalid position
Enter again 3
Enter the character k
Output:
Frame after stuffing is:
d l e s t x a s d l e k d l e d le e f g h d l e e t x













Computer Networks

KITS ENGG COLLEGE Page No:


AIM:- Implement the data link layer framing methods such as Bit Stuffing.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int n,i,j,c,count,a[20],b[30];
clrscr();
printf(enter the frame length);
scanf(%d,&n);
printf(enter input frame is 1s,0s only);
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++)
Computer Networks

KITS ENGG COLLEGE Page No:

{
j++;
b[j]=a[k];
count++;
if(count ==5)
{
J++;
b[j]=0;
}
I=k;
}
}
else
{
b[j]=a[i];
}
I++;
J++;
}
printf(after stuffing the frame is:);
for(i=0;i<j;i++)
printf(%d,b*j+);
getch();
}
Computer Networks

KITS ENGG COLLEGE Page No:



Output:
Enter frame length:10
Enter input frame (0s,1s)
1010111111
After stuffing the frame:1010111111

















Computer Networks

KITS ENGG COLLEGE Page No:


AIM:- To implement dijkstras algorithm to compute the shortest path.
PROGRAM:-
#include<stdio.h>
main()
{
char ch='y',sp[10],nb[10];
int ds[10],j=0,k,sm,i,n;
clrscr();
printf("enter the source node:");
sp[0]=getche();
j++;
do
{
printf("\nhow many neighbours:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter the neighbour name:");
nb[i]=getche();
printf("\n enter distance:");
scanf("%d",&ds[i]);
}
sm=ds[0];
Computer Networks

KITS ENGG COLLEGE Page No:

for(i=1;i<n;i++)
{
if(sm>ds[i])
{
sm=ds[i];k=i;
}
}
sp[j]=nb[k];
j++;
sp[j]='\0';
printf("\n shortest path is:");
for(i=0;sp[i]!='\0';i++)
printf("%c",sp[i]);
printf("\n do u want more neighbours?y/n");
ch=getche();
}while(ch=='y');
getch();
}






Computer Networks

KITS ENGG COLLEGE Page No:


OUTPUT:-
enter source node:A
enter how many neighbours:4
enter neighbor name:B
enter distance:2
enter neighbor name:C
enter distance:3
enter neighbor name:D
enter distance:4
enter neighbor name:E
enter distance:1
shortrest path is:AE
do you want more neighbours?y/n:n

You might also like