100% found this document useful (1 vote)
7K views4 pages

A) Program For Character Stuffing

The first document describes a program for character stuffing. It takes a string as input, asks the user to enter a position, and a character to insert. It inserts the character at the given position, adding additional characters before and after to mark the start and end of the stuffed character. The second document describes a program for bit stuffing. It takes a binary frame as input and stuffs additional 0 bits after runs of 5 consecutive 1s. It outputs the stuffed frame.

Uploaded by

Akash Tiwari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
7K views4 pages

A) Program For Character Stuffing

The first document describes a program for character stuffing. It takes a string as input, asks the user to enter a position, and a character to insert. It inserts the character at the given position, adding additional characters before and after to mark the start and end of the stuffed character. The second document describes a program for bit stuffing. It takes a binary frame as input and stuffs additional 0 bits after runs of 5 consecutive 1s. It outputs the stuffed frame.

Uploaded by

Akash Tiwari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

a) PROGRAM FOR CHARACTER STUFFING

 #include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
clrscr();
printf("enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position, Enter again :");
scanf("%d",&pos);
}
printf("enter the character\n");
ch=getchar();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
 {
if(i==pos-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';
j=j+7;
}
 if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
  } 
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("\nframe after stuffing:\n");
printf("%s",b);
getch();
}
INPUT:
enter string:asdlefgh
enter position: 8
invalid position,enter again: 3
enter the character: k
OUTPUT:
frame after stuffing: dlestx as dle k dle dle dlefgh dleetx

 
b) PROGRAM FOR BIT STUFFING
 
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
 {
int a[20],b[30],i,j,k,count,n;
clrscr();
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]);
getch();
 }
 
INPUT:
Enter frame length: 10
Enter input frame (0's & 1's only):
1010111111
 
OUTPUT:
After stuffing the frame is:
10101111101

You might also like