#include%26lt;stdio.h%26gt;
void bitprint(long);
unsigned char bitcount(long);
main()
{
unsigned long rem=0,rx=0,mes=0,gen=0x11021;
unsigned char g1;
clrscr();
printf("\n Enter the message in hex:");
scanf("%x",%26amp;mes);
printf("\nGenerator polynomial is:%x",gen);
g1=bitcount(gen);
mes%26lt;%26lt;=(g1-1);
rem=mes;
while(rem%26gt;=gen)
rem=(rem^(gen%26lt;%26lt; (bitcount(rem)-g1)));
printf("\n Transmitted frame is :%x\n",(mes+rem));
bitprint((mes+rem));
printf("\n Enter the recived data in hex:");
scanf("%x",%26amp;rx);
rem=rx;
while(rem%26gt;=gen)
rem=(rem^(gen%26lt;%26lt; (bitcount(rem)-g1)));
if(rem==0)
printf("\n NO ERROR\n");
else
printf("\n ERROR HAS OCCURED\n");
return 0;
}
void bitprint(long a)
{
int bin[40],i=0;
while(a)
{
bin[i++]=a%2;
a/=2;
}
for(i=i-1;i%26gt;=0;i--)
printf("%d",bin[i]);
}
unsigned char bitcount(long a)
{
unsigned char count=0;
while(a)
{
count++;
a/=2;
}
return count;
}
The program below,runs in linux but does not give correct output in window(turbo C).?
I see others have given you competent answers about clrcscr() and conio.h
I just want to add that, when I compile in Turbo C and run on my machine (OS: WinXP) the program seems to never break the while(rem%26gt;=gen) loop in main(). Don't know if this might be part of the problem, or not. I've modified this portion of code to let you watch as it runs, like so:
...
...
...
mes%26lt;%26lt;=(g1-1);
rem=mes;
while(rem%26gt;=gen)
{
printf("\rCur rem: %ld", rem);
rem=(rem^(gen%26lt;%26lt; (bitcount(rem)-g1)));
}
printf("\n Transmitted frame is :%x\n",(mes+rem));
bitprint((mes+rem));
....
....
....
Hope maybe it helps a little...
Reply:clrscr() is not a standard function. It is declared in conio.h. This header is available with Turbo C only.
So, this code will not run on Linux and will run on Windows with Turbo C if you #include%26lt;conio.h%26gt;.
To make it run on Linux, don't use clrscr().
Reply:it seems that some of the required header files are missing. Eg conio.h , etc..
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment