Aim: Program:: Implement The Data Link Layer Framing Methods Such As Character Count
Aim: Program:: Implement The Data Link Layer Framing Methods Such As Character Count
Character Count.
PROGRAM:
#include<stdio.h>
int main()
{
char str[100];
int n,i,j,c=0,count=0;
printf("Enter the String:");
scanf("%s",str);
printf("Enter the number of frames:");
scanf("%d",&n);
int frames[n];
printf("Enter the frames size of the frames:\n");
for(i=0;i<n;i++)
{
printf("Frame %d:",i);
scanf("%d",&frames[i]);
}
printf("\nThe number of frames : %d\n",n);
for(i=0;i<n;i++)
{
printf("The content of the frame %d:",i);
j=0;
while(c<strlen(str) && j<frames[i])
{
printf("%c",str[c]);
if(str[c]!='\0')
{
count++;
OUTPUT:
Enter the frames size of the frames:
Frame 0:5
Frame 1:5
Frame 2:5
PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
int i,k=0,n,j=6;
char s[100],res[100]="",a[100]="";
printf("Enter the string:");
gets(s);
strcpy(res,"dlestx");
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='d' && s[i+1]=='l' && s[i+2]=='e')
{
res[j]='d';
res[j+1]='l';
res[j+2]='e';
j=j+3;
}
res[j]=s[i];
j++;
}
strcat(res,"dleetx");
printf("Stuffed char:%s",res);
n=strlen(res);
for(i=6;i<n-6;i++)
{
if(res[i]=='d' && res[i+1]=='l' && res[i+2]=='e')
OUTPUT 1:
Enter the string:hello
Stuffed char:dlestxhellodleetx
Destuffed char:hello
OUTPUT 2:
Enter the string:hellodle
Stuffed char:dlestxhellodledledleetx
Destuffed char:hellodle
PROGRAM:
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j=8,c=0,c1=0,k=8;
char s[100],res[100];
printf("Enter string:");
scanf("%s",s);
n=strlen(s);
strcpy(res,"01111110");
strcat(res," ");
for(i=0;i<n;i++)
{
res[j]=s[i];
j++;
if(s[i]=='1')
{
c+=1;
if(c==5)
{
res[j]='0';
j++;
c=0;
}
}
else
{
c=0;
OUTPUT 1:
Enter string:011111101
Stuffed string:01111110011111010101111110
Destuffed string:011111101
OUTPUT 2:
PROGRAM :
#include<stdio.h>
#include<math.h>
int r=0,m=0;
int data[10];
int dataatrec[10];
int no_pbits()
{
while(1)
{
if(m+r-1<=pow(2,r))
return ;
r+=1;
}
}
void is_pbit()
{
int i;
for (i=0;i<r;i++)
data[m+r-(int)pow(2,i)]=-1;
}
void pbits()
{
for(int i=0;i<r;i++)
{
int p=pow(2,i);
int q=m+r-p-1;
int d=0,cnt=0;
while(cnt!=p-1)
int c,i;//,c1,c2,c3,i;
printf("Enter number of bits:\n");
scanf("%d",&m);
no_pbits(8);
is_pbit();
int count=0;
printf("Enter data bits\n");
for(i=0;i<(m+r);i++)
{
if(data[i]!=-1)
{
scanf("%d",&data[i]);
count+=1;
}
if(count==m)
break;
OUTPUT 2:
Enter number of bits:
7
Enter data bits
1
0
1
0
1
1
0
Data bits after adding parity bits:1
0
1
0
0
1
1
0
0
0
1
Enter the received data bits one by one
1
0
PROGRAM :
#include <stdio.h>
void func(int[],int,int[],int);
void main()
{
int i,g,l,f=0,d[20],p[20],r[20];
printf("Enter the length of the generator: ");
scanf("%d",&g);
printf("Enter the generator: ");
for(i=0;i<g;i++)
{
scanf("%d",&p[i]);
}
printf("Enter the length of the dataword: ");
scanf("%d",&l);
printf("Enter the dataword: ");
for(i=0;i<l;i++)
{
scanf("%d",&d[i]);
r[i]=d[i];
}
for(i=l;i<(l+g-1);i++)
d[i]=0;
printf("Code word:");
for(i=0;i<(l+g-1);i++)
{
printf("%d ",d[i]);
}
else
r[k]=1;
}}}}
OUTPUT 1:
Enter the length of the generator: 5
Enter the generator: 1
0
0
1
1
Enter the length of the dataword: 10
Enter the dataword: 1
1
0
1
0
1
1
1
1
1
Code word:1 1 0 1 0 1 1 1 1 1 0 0 0 0
CRC: 0 0 1 0
Result of dataword: 1 1 0 1 0 1 1 1 1 1 0 0 1 0
Received dataword: 1
1
0
1
0
OUTPUT 2:
Enter the length of the generator: 5
Enter the generator: 1
0
0
1
1
Enter the length of the dataword: 10
Enter the dataword: 1
1
0
1
0
1
1
1
1
1
Code word:1 1 0 1 0 1 1 1 1 1 0 0 0 0
CRC: 0 0 1 0
#include<stdio.h>
int main()
{
int w,i,f,frames[50];
printf("Enter window size: ");
scanf("%d",&w);
printf("Enter number of frames to transmit: ");
scanf("%d",&f);
printf("Enter %d frames: ",f);
for(i=1;i<=f;i++)
{
scanf("%d",&frames[i]);
}
printf("With sliding window protocol the frames will be sent in
the following manner (assuming no correction of frames)\n");
printf("After sending %d frames at each stage sender waits for
acknowledgement sent by the receiver\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received
by sender\n");
}
else
{
printf("%d ",frames[i]);
}
}
if(f%w!=0)
}OUTPUT: