Bit stuffing program in c




BIT STUFFING

#include
main()
{
int n=0,i,size;
char ch,b[100];
FILE *ed;
FILE *es;
printf("enter the bit information size\n");
scanf("%d",&size);
printf("enter the information in bits\n");
for(i=0;i{
scanf("%c",&b[i]);
}
ed=fopen("info.txt","w+");
i=0;
for(i=0;i{
fputc(b[i],ed);
}
fclose(ed);
ed=fopen("info.txt","r+");
if(ed==NULL)
printf("error\n");
es=fopen("infoo.txt","w+");
ch=getc(ed);
while(ch!=EOF)
{
fputc(ch,es);
if(ch=='1')
n++;
else
n=0;
if(n==5)
{
fputc('0',es);
n=0;
}
ch=getc(ed);
}
printf("\n original data");
fclose(ed);
fclose(es);
ed=fopen("info.txt","rb+");
es=fopen("infoo.txt","rb+");



ch=getc(ed);
while(ch!=EOF)
{
printf("%c",ch);
ch=getc(ed);
}
printf("\n data after stuffing");
ch=getc(es);
while(ch!=EOF)
{
printf("%c",ch);
ch=getc(es);
}
fclose(ed);
fclose(es);
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: