Some code cn

 //Bit stuffing

#include<stdio.h>

#include<string.h>

void main()

{

int a[20],b[30],i,j,k,count,n;

printf("Enter frame length:");

scanf("%d",&n);

printf("Enter input frame (0's & 1's 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++)

{

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[i]);

}

Output:

Enter frame length:5

Enter input frame (0's & 1's only):

1

1

1

1

1

After stuffing the frame is: 111110











//Byte stuffing

#include<stdio.h>

#include<string.h>

#include<conio.h>

void main()

{

int j,l,m,c,k;

char a[50],b[50];

printf("Enter the string:");

scanf("%s",a);

strcpy(b,"DLESTX");

m=strlen(a);

for(j=0;j<m;)

{

if(a[j]=='d')

{

if(a[j+1]=='l')

{

if(a[j+2]=='e')

{

c=j+2;

for(l=0;l<3;l++)

{

for(k=m;k>c;k--)

{

a[k]=a[k-1];

}

m++;

a[m]='\0';

c+=1;

}

a[j+3]='d';

a[j+4]='l';

a[j+5]='e';

a[m]='\0';

j+=5;

}

}

}

j++;

}

strcat(b,a);

strcat(b,"DLEETX");

printf("\n%s",b);

printf("\nReceiver side:");

m=strlen(a);

for(j=0;j<m;)

{

if(a[j]=='d')

{

if(a[j+1]=='l')

{

if(a[j+2]=='e')

{

c=j;

for(l=0;l<3;l++)

{

for(k=c;k<m;k++)

a[k]=a[k+1];

}

c++;

}

j=c;

}

}

j++;

}

printf("\n%s",a);

getch();

}

OUTPUT:

Enter the string: ABC

DLESTXABCDLEETX

Receiver side:

ABC

Comments

Popular posts from this blog

Char count

Fork