Badrichit
Badrichit
#include<stdio.h> cnt=0;
#include<math.h> }
#include<string.h> }
main() else
{ {
int i=0,j=0,k=0,cnt=0; dstmsg[k++]=stmsg[j];
char cnt=0;
msg[100],stmsg[100],dstmsg[100],flag[10]="01111 }
110"; }
clrscr(); dstmsg[k]='\0';
printf("\nEnter the bit stream:"); printf("\nDestuffed message is :
scanf("%s",msg); %s",dstmsg);
/stuffing/ getch();
for(i=0;flag[i]!='\0';i++) }
{ CHARACTER STUFFING
stmsg[i]=flag[i];
} #include<stdio.h>
#include<math.h>
for(j=0;msg[j]!='\0';j++)
{ #include<string.h>
if(msg[j]=='1')
{ main()
++cnt; {
stmsg[i++]=msg[j];
if(cnt==5) int i=0,j=0,k=0,l=0;
{
char
stmsg[i++]='0';
msg[100],stmsg[100],dstmsg[100],stx,etx,
cnt=0;
dle;
}
} printf("\nEnter the starting element of
else text:");
{
stmsg[i++]=msg[j]; stx=getche();
cnt=0;
printf("\nEnter the data link enable
}
text:");
}
for(k=0;flag[k]!='\0';k++) dle=getche();
{
stmsg[i++]=flag[k]; printf("\nEnter the ending element of
} text:");
etx=getche();
stmsg[i]='\0';
printf("\nStuffed bit stream is : printf("\nEnter the mesage:");
%s",stmsg);
/destuffing/ gets(msg);
cnt=0;
/*Stuffing*/
k=0;
for(j=8;j<i-8;j++) stmsg[j++]=dle;
{
if(stmsg[j]=='1') stmsg[j++]=stx;
{
for(i=0;msg[i]!='\0';i++)
++cnt;
dstmsg[k++]=stmsg[j]; {
if(cnt==5) stmsg[j++]=msg[i];
{
if(msg[i]==stx || msg[i]==etx || char
msg[i]==dle) msg[100],gen[100],app[100],azero[100];
{ int i,j,lmsg,lgen,lapp,lappr;
stmsg[j++]=msg[i]; printf("\nEnter the bit stream:");
} scanf("%s",msg);
} printf("\nEnter the generator:");
stmsg[j++]=dle; scanf("%s",gen);
stmsg[j++]=etx;
lgen=strlen(gen);
stmsg[j]='\0';
lmsg=strlen(msg);
printf("\nStuffed message is:");
for(i=0;i<(lgen-1);i++)
puts(stmsg);
azero[i]='0';
/*destuffing*/
azero[i]='\0';
for(k=2;k<j-2;k++)
strcat(msg,azero);
{
strcpy(app,msg);
dstmsg[l++]=stmsg[k];
lapp=strlen(app);
if(stmsg[k]==stx || stmsg[k]==etx
|| stmsg[k]==dle) for(i=0;i<=(lapp-lgen);i++)
{
{ if(app[i]=='1')
k++; {
} for(j=0;j<lgen;j++)
} {
dstmsg[l]='\0';
puts(dstmsg); app[i+j]='0';
getch(); else
} app[i+j]='1';
CRC }
#include<stdio.h> }
#include<math.h> }
#include<ctype.h> for(i=lmsg;i<(lmsg+lgen-1);i++)
#include<string.h> printf("%c",app[i]);
main() for(i=lmsg;i<(lmsg+lgen);i++)
{ msg[i]=app[i];
printf("\nChecksum appended bit stream else
is : %s",msg);
printf("\nReceived bit
printf("\nEnter the received bit stream:"); stream is free of error:");
scanf("%s",app); }
lappr=strlen(app); getch();
if(lappr!=lapp) }
int main()
for(j=0;j<lgen;j++)
{
{
int wait_time,i=1;
if(app[i+j]==gen[j])
ACK==YES;
app[i+j]='0'; for(i=1 ;i<=TOT_FRAMES;i++)
else {
{ {
Sleep(RTT/2); if(i<j)
printf("\n RECEIVER : {
Frame%d received, ACK sent\n",i);
printf("\nCost
printf("----------------------- b/w nodes %d to %d is:",i,j);
--------");
ACK=YES; scanf("%d",&net[i][j]);
Sleep(RTT/2);
net[j][i]=net[i][j];
}
net[i][i]=0;
}
net[j][j]=0;
return 0;
}
}
}
}
SHORTEST PATH
printf("\nEnter the src: node:");
#include<stdio.h>
scanf("%d",&src);
#include<math.h>
printf("\nEnter the dst: node:");
#include<ctype.h>
scanf("%d",&dst);
#include<string.h>
for(i=1;i<=n;i++)
#include<conio.h>
{
main()
nodeinfo[i].pred=0;
{
nodeinfo[i].len=9999;
struct
nodeinfo[i].lab='t';
{
}
int pred,len;
k=dst;
char lab;
nodeinfo[dst].len=0;
}nodeinfo[20];
nodeinfo[dst].lab='p';
int n,i,j,k,min,inf=9999,src,dst;
do
int net[20][20];
{
printf("\nEnter the no: of nodes:");
for(i=1;i<=n;i++)
scanf("%d",&n);
{
printf("\nEnter the cost matrix:");
if( (nodeinfo[i].lab=='t')
for(i=1;i<=n;i++)
&& (net[k][i]!=0) )
{
{
if( BELLMAN FORD'S ALGORITHM
(net[k][i]+nodeinfo[k].len)<nodeinfo[i].len )
#include<stdio.h>
{
struct node
{
nodeinfo[i].len=nodeinfo[k].len+net[k][i];
unsigned dist[20];
nodeinfo[i].pred=k; unsigned from[20];
} }rt[10];
} int main()
} {
min=inf; int costmat[20][20];
for(i=1;i<=n;i++) int nodes,i,j,k,count=0;
{ printf("\nEnter the number of nodes : ");
if( (nodeinfo[i].lab=='t') scanf("%d",&nodes);//Enter the nodes
&& (nodeinfo[i].len<min) )
printf("\nEnter the cost matrix :\n");
{
for(i=0;i<nodes;i++)
k=i;
{
min=nodeinfo[i].len; for(j=0;j<nodes;j++)
} {
} scanf("%d",&costmat[i][j]);
nodeinfo[k].lab='p'; costmat[i][i]=0;
} for(j=0;j<nodes;j++)
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}while(count!=0);
for(i=0;i<nodes;i++)
for(j=0;j<nodes;j++)
printf("\n\n");
getch();