Wednesday, April 6, 2016

W.A.P to implement Character Stuffing Algorithm.



#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char s[30],s1[50],s2[30],ch;
int i,j,k=0,n;
clrscr();
printf("\nSender side:");
printf("\nEnter frame:");
scanf("%s",s);
flushall();
printf("\nEnter flag:");
scanf("%c",&ch);
n=ch-48;
for(i=0;s[i]!='\0';)
{
s1[k]=ch;
k++;
for(j=1;j<n;j++)
{
s1[k]=s[i];
k++;
i++;
}
}
s1[k]='\0';
printf("Frame after character stuffing is: %s",s1);
printf("\nReciver side:");
printf("\nFrame recived is: %s",s1);
ch=s1[0];
//printf("\n %c",ch);
k=0;
for(i=0;s1[i]!='\0';i++)
{
if(ch!=s1[i])
{
//printf("\n %c",s1[i]);
s2[k]=s1[i];
k++;
}
}
s2[k]='\0';
printf("\nFrame after character destuffing is: %s",s2);
getch();
}

No comments:

Post a Comment