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 #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com
after for loop plz initilize the count to 1.the it will work for any number of bits having
5 continuous 1′s
after for loop plz initilize the count to 1.the it will work for any number of bits having
5 continuous 1′s…………
in the bit stuffing program put count=0,then it will run correctly,i.e.it will put 0 after 011111
Thanku darling
the code is not showing the correct result for string length greater then 10
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();
#include
#include
#include
#include
#include
#include “myheader.h”
int main()
{
char str1[50],str2[50];
int i=0,j=0,len,count=0;
int open_status,mknod_status;
printf(“Enter The String : “);
scanf(“%s”,str1);
len=strlen(str1);
printf(“Displaying Bit Values :\n”);
for(i=0;i<len;i++)
{
printf("Bit Values For %c : ",str1[i]);
displaybit(str1[i]);
printf("\n");
}
printf("\nReplacing bit :\n");
for(i=0;i<len;i++)
{
for(j=0;j<=7;j++)
{
if((getbit(str1[i],j)==1))
{
count++;
}
if(count==5)
{
insertbit(count+1,str1[j],0);
count=0;
}
//count++;
}
}
printf("Displaying Bit Values After Changing bit :\n");
for(i=0;i<len;i++)
{
printf("Bit Values For %c : ",str1[i]);
displaybit(str1[i]);
printf("\n");
}
str2[0]='~';
for(i=1;i<len;i++)
{
str2[i]=str1[i-1];
}
str2[i]='~';
len=strlen(str2);
for(i=0;i<len;i++)
{
printf("Character Bit : %c \n",str2[i]);
}
printf("\nNew String: %s",str2);
mknod_status=mknod("pipe",S_IFIFO|S_IRWXU,0);
if(mknod_status<0)
{
printf("error in pipe ");
}
open_status=open("pipe",O_WRONLY);
if(open_status<0)
{
printf("error in open ");
}
write(open_status,str2,sizeof(str2));
close(open_status);
return 0;
}
coding is too lengthy
abe ye kya gandu program h
….
i want alogrithm for this program
11110