CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    32

    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() */

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Trying to append crc to test data.

    Did you mean to double post?

  3. #3
    Join Date
    Apr 2009
    Posts
    598

    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
  •  





Click Here to Expand Forum to Full Width

Featured