riteshshah
Programmer
thread205-1155185.
Spoke to Dave Sinkula and he gave me a great function to convert hex to bin (below). It's taken a while for me to get round to finishing this but I seem to have conversion errors when I look at the binary file. Some of the end of the pages look corrupt. - Usually the last line.
Any ideas why this may occur?
Thanks folks!
#include <stdio.h>
int main(void)
{
static const char infilename[] = "file.txt";
static const char outfilename[] = "file.bin";
FILE *infile = fopen(infilename, "r");
FILE *outfile = fopen(outfilename, "wb");
if ( infile && outfile )
{
int ch;
while ( fscanf(infile, "%2x", &ch) == 1 )
{
fputc(ch, outfile);
}
fclose(infile);
fclose(outfile);
}
return 0;
}
Spoke to Dave Sinkula and he gave me a great function to convert hex to bin (below). It's taken a while for me to get round to finishing this but I seem to have conversion errors when I look at the binary file. Some of the end of the pages look corrupt. - Usually the last line.
Any ideas why this may occur?
Thanks folks!
#include <stdio.h>
int main(void)
{
static const char infilename[] = "file.txt";
static const char outfilename[] = "file.bin";
FILE *infile = fopen(infilename, "r");
FILE *outfile = fopen(outfilename, "wb");
if ( infile && outfile )
{
int ch;
while ( fscanf(infile, "%2x", &ch) == 1 )
{
fputc(ch, outfile);
}
fclose(infile);
fclose(outfile);
}
return 0;
}