CodePudding user response:
Try to use the most basic sprintf function "% 02 x" formatCodePudding user response:
If use of MFC CFile class, how to do?CodePudding user response:
The data are converted to 0 XFF hexadecimal
CodePudding user response:
Yes, how to do, can guide it to me?CodePudding user response:
Fyi:# include & lt; stdio.h>
#include
#include
The FILE * fi * fo;
Unsigned int n;
Int c;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void main (int arg c, char * argv [])
{
If (argc<3) {
Cprintf (" Bin2Hex srcfile desfile ");
return;
}
If ((fi=fopen (argv [1], "rb"))==NULL) {
Cprintf (" Can not find the file % s ", argv [1]).
return;
}
If ((fo=fopen (argv [2], "w"))==NULL) {
The fclose (fi);
Cprintf (" Can not create the file % s ", argv [2]).
return;
}
n=0;
While (1) {
C=fgetc (fi);
If (EOF==c) break;
n++;
If (1==n) fprintf (fo, "0 x % 02 x", c);
The else {
If (1==n % 16) fprintf (fo, "\ % n0x 02 x", c);
The else fprintf (fo, "02, 0 x % x", c);
}
}
Fcloseall ();
Cprintf (" OK to Bin2Hex % u bytes. The ", n);
}