Skip to content

Instantly share code, notes, and snippets.

@ma34s
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ma34s/10008824 to your computer and use it in GitHub Desktop.
Save ma34s/10008824 to your computer and use it in GitHub Desktop.
バイナリのHex化された文字列を変換して表示 (エラー処理なし、文字列にならないものは排除)
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
FILE* fp = fopen(argv[1],"rb");
char c[3] = {0,};
char* e;
int i;
int read;
int cnt=0;
int flg = 0;
while( 1 )
{
i = fread( c, 1,2,fp );
if( i == 2 )
{
i = strtol(c,&e,16);
if( (0x20<= i) && (i<=0x7e))
{
flg=1;
printf("%c",i);
}
else
{
if( flg == 1 )
{
printf("\n");
flg = 0;
}
}
}
else
{
break;
}
}
close(fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment