Hey, Some one Please help in Completing this code of CRC
char* substr(char* pra,int strt,int end)//To Evaluate Substring
{
char pr[5]="\0";
int j,k;
for(j=strt,k=0;j<=end&&k<5;j++,k++)
pr[k]=pra[j];
return pr;
}
char* exor(char* pra,char* div)//To Evaluate Mod2 Operation
{
char out[5]="\0";
int i;
for(i=0;i<strlen(pra);i++)
{
if(pra[i]==div[i])
out[i]='0';
else
out[i]='1';
}
return out;
}
void main()
{
char *gen,*fra="\0",*temp="\0",*quo="\0",*x;
int i,j,flag,cntr=0;
clrscr();
printf("Enter the Frame");
scanf("%s",fra);
printf("Enter the Generator");
scanf("%s",gen);
for(i=1;i<strlen(gen);i++)
strcat(fra,"0");
for(i=0;i<strlen(fra)-4;i++)
{
x=substr(fra,i,i+4);
temp=exor(substr(fra,i,i+4),gen);
if(temp[0]=='0'&&temp[1]!='0')
strcat(quo,'1');
else
{
flag=0;
for(j=0;j<strlen(quo);j++)
{
if(temp[i]=='0'&&flag==0)
cntr++;
else{
flag=1;
break;
}
}
for(j=0;j<cntr;j++)
strcat(quo,'0');
i=i+cntr;
}
}
printf("%s",quo);
}