C Program – Cyclic Redundency Check

by Nideesh C on April 17, 2011 · 0 comments

in C Programming




#include<stdio.h>
#include<conio.h>
int gen[4],genl,frl,rem[4];
void main()
{
int  i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
clrscr();
frl=8;  genl=4;
printf("enter frame:");
for(i=0;i<frl;i++)
{
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
}
printf("enter generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
 
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
{
dupfr[i]=0;
}
remainder(dupfr);
 
for(i=0;i<frl;i++)
{
recfr[i]=fr[i];
}
for(i=frl,j=1;j<genl;i++,j++)
{
recfr[i]=rem[j];
}
remainder(recfr);
flag=0;
for(i=0;i<4;i++)
{
if(rem[i]!=0)
flag++;
}
if(flag==0)
{
printf("frame received correctly");
}
else
{
printf("the received frame is wrong");
}
 
getch();
}
 
remainder(int fr[])
{
int k,k1,i,j;
for(k=0;k<frl;k++)
{
if(fr[k]==1)
{
k1=k;
for(i=0,j=k;i<genl;i++,j++)
{
rem[i]=fr[j]^gen[i];
}
 
for(i=0;i<genl;i++)
{
fr[k1]=rem[i];
k1++;
}
}
}
}

INPUT:
 enter frame :
 1 1 1 1 1 1 1 1
 enter generator :
 1 1 0 1

OUTPUT:
 frame received correctly



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program – Finding remainder
  2. C Program to accept two matrices and check if they are equal
  3. C program to check whether a given integer is odd or even
  4. C program to check whether a given number is prime or not and output the given number with suitable message
  5. C program to find the length of a string without using the built-in function also check whether it is a palindrome or not

Leave a Comment

Previous post:

Next post: