I would first read the header and then in a loop the data. You can read hexadecimal numbers with the "x"-specifier (say your file is named hexfile.txt
):
#include <stdio.h>
int main ()
{
FILE *stream;
unsigned int h, l, d;
if( (stream = fopen( "hexfile.txt", "r" )) == NULL ) return 1;
while (EOF != fscanf (stream, " %x %x", &h, &l))
{
printf ("%02X %02X
",h,l);
for (unsigned i=0; i<l; ++i)
{
if (EOF == fscanf (stream, " %x", &d)) break;
printf ("%02X ",d);
}
puts ("");
}
fclose (stream);
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…