SlavaSoft FastCRC Library Online Help

Prev Page Next Page
FastCRC Library API

The following sample demonstrates how to use the CRC16C API to calculate the CRC16C 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;

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

        SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

        printf( "%s", checksumhex );

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

        SL_FCRC16C_Init( &crcvar );

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

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

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

        SL_FCRC_ConvertToHex16( checksumhex, checksum, 0 );

        printf( "%s", checksumhex );


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

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

    return 0;




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