-
February 2nd, 2010, 09:00 AM
#1
Trying to append crc to test data.
I am having trouble trying to get the CRC append to the test data, and print out the data with the appended crc.
#include <stdio.h>
#include <string.h>
#include "crc.h"
static unsigned long crcSum;
void
main(void)
{
// unsigned char test[] = "123456789";
unsigned char test[13] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
/*
* Print the check value for the selected CRC algorithm.
*/
printf("Payload: 0x%X\n", test);
printf("The crcFast() of \"123456789\" is 0x%X\n", crcFast(test, strlen(test)));
crcSum = crcFast(test, strlen(test));
// printf("Payload is 0x%X\n", test);
// printf("CRC is 0x%X\n", crcSum);
// Add CRC To message
*(unsigned long *)&test[9] = (unsigned long)crcSum /*crcSum*/;
printf("Payload with CRC Appended: 0x%X\n", *(unsigned long *)&test[9]);
} /* main() */
-
February 2nd, 2010, 09:40 AM
#2
Re: Trying to append crc to test data.
Did you mean to double post?
-
February 2nd, 2010, 09:42 AM
#3
Re: Trying to append crc to test data.
strlen() counts bytes until a null character.
Unfortunately there is no null charater in test[]
Instead of
Code:
unsigned char test[13] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9};
write
Code:
unsigned char test[13] = {0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9, 0x0};
N.B. Write your code between [code] and [/code].
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|