ich habe folgendes Anliegen.
Ich habe mit Hilfe eines Algorihmen CRC berechnet und diese in einem Array abgespeichert: TableHeaderCRC[256].
Die Werte befinden sich in diesem Array
Jetzt wurde ich genre dieses Array in main C Code einfügen.
Code: Alles auswählen
static const unsigned char HeaderCRC_Table[256] =
{
0x00, 0xfe, 0xff, 0x01, 0xfd, 0x03, 0x02, 0xfc,
0xf9, 0x07, 0x06, 0xf8, 0x04, 0xfa, 0xfb, 0x05,
0xf1, 0x0f, 0x0e, 0xf0, 0x0c, 0xf2, 0xf3, 0x0d,
0x08, 0xf6, 0xf7, 0x09, 0xf5, 0x0b, 0x0a, 0xf4,
usw.
Ich wollte das in einer Datei abspeichern und dann einfach daraus kopieren und ins source code einfügen.
Es klappt nicht ganz:
1. Es sollen hex werte sein wenn ich das als .dat abspechere werden die Werte nicht als hex dagestellt.
2. Der letzte Wert ist nicht in der Datei
Vielen Dank für die Hilfe.
Code: Alles auswählen
#include <stdio.h>
#define MAX_ARRAY 255
unsigned char TableHeaderCRC[256];
unsigned char main ( void )
{
FILE *fp;
unsigned char dataValue = 0x00;
unsigned char crcValue = 0xFF;
unsigned char i;
int c;
for ( i=0; i<MAX_ARRAY; i++ )
{
unsigned int crc;
crc = crcValue ^ dataValue; /* XOR C7..C0 with D7..D0 */
/* Exclusive OR the terms in the table (top down) */
crc = crc ^ (crc << 1) ^ (crc << 2) ^ (crc << 3)
^ (crc << 4) ^ (crc << 5) ^ (crc << 6) ^ (crc << 7);
/* Combine bits shifted out left hand end */
TableHeaderCRC [MAX_ARRAY - i] = (crc & 0xfe) ^ ((crc >> 8) & 1);
dataValue++;
}
AB HIER:
if ((fp = fopen("TableHeaderCRC.dat", "w")) == NULL)
return 1;
else
{
for ( i=0; i<MAX_ARRAY; i++ )
{
putc(TableHeaderCRC[i],fp);
}
}
return 0;
}