OUTPUT:
Enter frame length: 10
Enter input frame (0′s & 1′s only):
1 0 1 0 1 1 1 1 1 1
After stuffing the frame is:
1 0 1 0 1 1 1 1 1 0 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #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(); } |
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
February 21st, 2011 at 9:49 pm
after for loop plz initilize the count to 1.the it will work for any number of bits having
5 continuous 1′s
February 21st, 2011 at 9:49 pm
after for loop plz initilize the count to 1.the it will work for any number of bits having
5 continuous 1′s…………
February 23rd, 2011 at 8:03 pm
in the bit stuffing program put count=0,then it will run correctly,i.e.it will put 0 after 011111
April 10th, 2011 at 4:24 am
Thanku darling
December 22nd, 2011 at 3:26 pm
the code is not showing the correct result for string length greater then 10
January 24th, 2012 at 10:00 am
Chosen by Asker
#include
#include
void main()
{
char num[11], i, j, k, cnt=0;
clrscr();
printf(“Enter the sequence of 10 digit binary numbers: “);
for(i=0;i<10;i++)
scanf("%c", &num[i]);
printf("The 10 digit binary number you have entered is: ");
for(i=0;i<10;i++)
printf("%c", num[i]);
printf("\nAfter stuffing: ");
i=0;
while (ii;k–)
num[k]=num[k-1];
num[i]=0;
num[i]=’0′;
}
}
else
{
i++;
cnt=0;
}
}
for(i=0;i<11;i++)
printf("%c", num[i]);
printf("\nAfter destuffing: ");
i=0;
while (i<10)
{
if(num[i]=='1')
{
i++;
cnt++;
if(cnt==5)
{
for(k=i;k<11;k++)
num[k]=num[k+1];
}
}
else
{
i++;
cnt=0;
}
}
for(i=0;i<10;i++)
printf("%d", num[i]-48);
getch();