Hi, I am trying to implement a crc check but I am not having the correct output. i.e. I am having a "Corrupted file" when the file is not corrupted, and vice versa. I am not "seeing" my mistake since according to me the logic is right. The wierd thing is that before I have implemented the CRC in a function it used to work...now that it is in a function I am having the opposite output. below is my code

before implemented into a function (when it used to work)

P.S adder is the counter of 'corrupted' bits in file.

if (adder != 0)
{
 printf("NOT Corrupted");
}
else
{
printf("Corrupted");
}

now that it is in a function (not working)

void CRC(int check)
{
	if (check != 0)
	{												printf("NOT Corrupted");
	}
	else
	{
		printf("Corrupted");
	}
// return 0;
	
}

Thanks a lot.

Please give the entire code. There is nothing wrong with the code segment that you have pasted here.

This is the part were I am calling the function. adder1 is a counter that contains the number of errors in the file. Then afterwards I am resetting the counter to 0 again so that it starts again from 0 when reading from another file.

CRC(adder1);
	 		if (adder1==0){
	 			nta=nta+0.025;
	 			printf("ACK to A arrives at %.3f\n", nta);
	 		}
	 		adder1=0;

Thanks a lot.

did you try displaying the value of int check, just to be sure its what you expect it to be?

void CRC(int check)
{
/*display check here*/
	if (check != 0)
	{												printf("NOT Corrupted");
	}
	else
	{
		printf("Corrupted");
	}
// return 0;
	
}

Your not really give us much to work with..

The only discrepancy that I can spot is that 'adder' is used in the if check (outside the function , in the first post) and 'adder1' is being passed to the function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.