#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<malloc.h>
struct s
{
int seq_no,frame[10],parity;
}s1[20],tmp[20];
struct poly
{
int data,p;
struct poly *link;
}*start;
void parityCount(struct s[]);
void print(struct s[]);
void sender(int *,int);
void reciver(struct s[]);
void poly();
void polydisplay();
int main()
{
char str[20];
int i,j,as,q,arr[10],a[50],n,k;
printf("Enter any string..");
scanf("%s",str);
start=NULL;
n=0;
printf("\n\n String in binary..\n\n");
for(j=0;str[j];j++)
{
i=0;
as=toascii(str[j]);
q=as;
while(q!=1)
{
arr[i++]=q%2;
q/=2;
}
arr[i++]=1;
for(k=i-1;k>=0;k--)
a[n++]=arr[k];
}
for(j=0;j<n;j++)
printf("%d",a[j]);
printf("\n");
sender(a,n);
poly();
polydisplay();
return 0;
}
int len;
void sender(int a[],int i)
{
int j,no=0,k;
len=i/10;
if(i%10==0)
len--;
for(j=0;j<=len;j++)
{
s1[j].seq_no=(j+1);
for(k=0;k<10;k++)
{
if(no!=i)
s1[j].frame[k]=a[no++];
}
}
parityCount(s1);
printf("\n Sending data..\n\n");
print(s1);
}
void poly() // For creating the polynomial using structure.
{
int i,j,k;
struct poly *q,*tmp;
printf("\nenterd into poly..\n");
for(i=0;i<=len;i++)
{
k=9;
for(j=0;j<10;j++)
{
if(start==NULL)
{
start=(struct poly*)malloc(sizeof(struct poly));
start->data=s1[i].frame[j];
start->p=k--;
start->link=NULL;
}
else
{
q=start;
while(q->link!=NULL)
q=q->link;
tmp=(struct poly*)malloc(sizeof(struct poly));
tmp->data=s1[i].frame[j];
tmp->p=k--;
tmp->link=NULL;
q->link=tmp;
}
}
}
}
void polydisplay() // Display the polynomial.
{
struct poly *temp;
temp=start;
int i=0;
while(temp!=NULL)
{
if(i==10)
{
i=0;
printf("\n");
}
if(temp->data!=0)
{
if(temp->p==0)
printf(" + 1");
else
printf(" x ^ %d +",temp->p);
}
temp=temp->link;
i++;
}
printf("\n");
}
void parityCount(struct s *s1)
{
int ans=0,j,k;
for(j=0;j<=len;j++)
{
for(k=0;k<10;k++)
ans=ans ^ s1[j].frame[k];
s1[j].parity=ans;
}
}
void print(struct s s1[])
{
int j,k;
for(j=0;j<=len;j++)
{
printf("\n\t%d \t ",s1[j].seq_no);
for(k=0;k<10;k++)
printf("%d",s1[j].frame[k]);
printf("\t %d ",s1[j].parity);
printf("\n");
}
}
0 comments:
Post a Comment