FastCRC Library API

The following sample demonstrates how to use the CRC16 API to calculate the CRC16 checksum for a string.

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

int main()
{
    char buff[ 256 ];

    char checksumhex[ SLC_FCRC_MAXHEXSIZE ]; /*0 terminated*/
    unsigned long checksum;
    unsigned long crcvar;

    do
    {
        /*****Get the string from the user****************************************/

        printf( "\nEnter a string: " );
        gets( buff );

        printf( "\nChecksum for \"%s\":", buff );

        /*****Calculate the checksum using CalculateStr***************************/

        printf( "\nCalculated using CalculateStr:        " );

        checksum = SL_FCRC16_CalculateStr( buff );

        SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

        printf( "%s", checksumhex );

        /*****Initialize the crcvar before calling Update and Final**************/

        SL_FCRC16_Init( &crcvar );

        /*****Calculate the checksum using Update and Final***********************/

        printf( "\nCalculated using Update and Final:    " );

        SL_FCRC16_Update( &crcvar, buff, strlen( buff ) );
        checksum = SL_FCRC16_Final( &crcvar ); /* SL_FCRC16_Final reinitializes the crcvar for the next use */

        SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

        printf( "%s", checksumhex );

        /*****Continue?***********************************************************/

        printf( "\nContinue (Y/N)?" );
        gets( buff );

    }while( *buff == 'y' || *buff == 'Y' );

    return 0;
}

 


 

 

Send Feedback to SlavaSoft Inc. Tell a friend about FastCRC Library