Last active
August 29, 2015 13:58
-
-
Save ma34s/10008824 to your computer and use it in GitHub Desktop.
バイナリのHex化された文字列を変換して表示 (エラー処理なし、文字列にならないものは排除)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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