小弟我想将txt中的二进制转换为十六进制,并在前面加上0X做标记

我想将txt中的二进制转换为十六进制,并在前面加上0X做标记
我想将txt中的二进制转换为十六进制,并在每一个十六进制数的前面加上0X做标号
请大家指教。
如果有源码就更感谢了。(只要转换及加标号的部分就行了,谢谢)

------解决方案--------------------
FILE* f;

if( ( f = fopen( "filename.txt ", "r " ) == NULL )
return;

while( !feof( f ) )
{
printf( "0x%02x ", fgetc( f ) );
}

fclose( f );


------解决方案--------------------
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
FILE *f = NULL, *ftmp = NULL;
char *tmpfn = NULL;
char *fn = "test.txt ";

if( ( f = fopen( "test.txt ", "r " ) ) == NULL )
exit( 1 );

if( ( tmpfn = tmpnam( NULL ) ) == NULL )
{
fclose( f );
exit( 1 );
}

if( ( ftmp = fopen( tmpfn, "w " ) ) == NULL )
{
fclose( f );
exit( 1 );
}

while( !feof( f ) )
{
fprintf( ftmp, "0x%02x ", fgetc( f ) );
}

fclose( ftmp );
fclose( f );

remove( fn );
rename( tmpfn, fn );

system( "PAUSE ");
return 0;
}
------解决方案--------------------
fopen的时候用 "rb "模式