Question
Please fix errors and also need a flowchart for the following hamming code. //hamming code #include #include #include struct node { int data; struct node
Please fix errors and also need a flowchart for the following hamming code.
//hamming code
#include
#include
#include
struct node
{
int data;
struct node *link;
};
struct node *first=NULL, *last=NULL, *cur=NULL, *next, *move,*new;
//Creation of linked list for the given data
void create()
{
int i=1;
cur=(struct node*)malloc(sizeof(struct node);
l1:for(i=1;i<=7;i++)
{
printf("Enter the%d", i "bit data");
scanf("%d", &cur->data);
//Checking for binary data
if(cur->data!=0||cur->data!=1)
{
printf("Invalid data ");
goto l1;
}
//Insertion in first position
if(i==1)
{
cur->link=NULL;
first=cur;
last=cur;
next=cur;
}
//Insertion in the middle
elseif(i!=7)
{
next->link=cur;
next=cur;
}
//Insertion at the end
else
{
next->link=cur;
next=cur;
last=cur;
}
}
}
//To generate the parity bits
void cal()
{
int count=0,i,x,flag,a,b,c,d;
move=first;
//Parity bit at position 8. Calculation:
for(x=0;x<3;x++)
{
if(move->data==1)
count++;
move=move->link;
}
if(count%2==0)
flag=0;
else
flag=1;
//Assigns the parity bit
new=(struct node*)malloc(sizeof(struct node);
new->data=flag;
new->link=move->link;
move->link=new;
move=new;
move=move->link;
//Parity bit at position 4.Calculation:
count=0;
flag=0;
for(x=0;x<3;x++)
{
if(move->data==1)
count++;
if(x==0) a=move->data;
if(x==1) b=move->data;
if(x==2) c=move->data;
move=move->link;
}
if(count%2==0)
flag=0;
else
flag=1;
//Assigns the parity bit
new=(struct node*)malloc(sizeof(struct node);
new->data=flag;
new->link=move->link;
move->link=new;
move=new;
move=move->link;
d=move->data;
//Parity bit at position 2:Calculation
count=0;
flag=0;
count =(d+b+a);
if(count%2==0)
flag=0;
else
flag=1;
//Assigns the parity bit
new=(struct node*)malloc(sizeof(struct node);
new->data=flag;
new->link=NULL
move->link=new;
move=new;
//Parity bit at position1:Calculation
count=0;
flag=0;
count=(d+c+a);
if(count%2==0)
flag=0;
else
flag=1;
//Assigns the parity bit
new=(struct node*)malloc(sizeof(struct node);
new->data=flag;
new->link=NULL;
move->link=new;
move=new;
count=0;
flag=0;
}
//detection of errors in transmitted data
void transmit()
{
int i,x,a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4;
int count=0, f1=f2=f3=f4=0;
l2:for(i=1;i<=11;i++)
{
printf("Enter the %d",i "value");
scanf("%d",x);
if(x!=0||x!=1)
goto l2;
elseif(i==1) a1=x;
elseif(i==2) a2=x;
elseif(i==3) a3=x;
elseif(i==4) a4=x;
elseif(i==5) b1=x;
elseif(i==6) b2=x;
elseif(i==7) b3=x;
elseif(i==8) b4=x;
elseif(i==9) c1=x;
elseif(i==10) c2=x;
elseif(i==11) c3=x;
count=c3+c2+c1+b4;
if(count%2==0)
f1=0;
else
f1=1;
count=0;
count=a4+b1+b2+b3;
if(count%2==0)
f2=0;
else
f2=1;
count=0;
count=a2+a3+b2+b3;
if(count%2==0)
f3=0;
else
f3=1;
count=0;
count=a1+a3+b1+b3;
f(count%2==0)
f4=0;
else
f4=1;
count=0;
count=[(f4*1)+(f3*2)+(f2*4)+(f1*8)
if(count>11)
printf("Invalid data");
else
printf("Error present in position : %d",count );
}
void main()
{
int a;
//Creation of interacive menu
do
{
printf("Press 1 to determine Hamming Code generated");
printf("Press 2 to determine error in the given code");
printf("Press 3 to exit");
scanf("%d", a);
if(a==1)
{
create();
cal();
}
if(a==2)
transmit();
if(a==3)
exit(0);
}
while(a!=3);
//End of program
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started