Welcome to my blog, enjoy reading.

Saturday, May 1, 2010

Cyclic Redundancy check Using C

#include< stdio.h>
#include< conio.h>
#include< string.h>


char I[40],d[40]="1100000001011";
char a[12]="000000000000",t[13];
int i=0,j,l,n,p;


void main()
{
    void division(void);
    clrscr();
    printf("\n enter a message string    : ");
    gets(I);
    n=strlen(I);
    printf("\nOriginal message             : %s \n",I);
    strcat(I,a);
    p=n+12;
    division();
    printf("\nThe reminder at sender is : %s \n",t);
    for(i=n,j=1;i     {
    I[i]=t[j];
    }
    printf("\nThe padded string to be sent : %s \n",I);
    division();
    printf("\nThe remainder string at receiver : %s\n",t);
    printf("\nThe received message is correct");
    getch();
}

void division(void)
{
    for(i=0;i <13;i++)
    t[i]=I[i];
    while(i 
  {
    for(l=0;l <13;l++)
    {
        if(t[l]==d[l])
         t[l]='0';
        else
         t[l]='1';
    }
    if(t[0]=='0')
    {
        for(j=0;j <12;j++)
         t[j]=t[j+1];

        t[j]=I[i++];
    }
    }
    while(t[0]=='1')
    for(l=0;l <13;l++)
    {
    if(t[l]==d[l])
        t[l]='0';
    else
        t[l]='1';
    }
    t[l]='\0';
}






0 comments:

Post a Comment