#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_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 );
/*****Continue?***********************************************************/
printf( "\nContinue (Y/N)?" );
gets( buff );
}while( *buff == 'y' || *buff == 'Y' );
return 0;
}
|