查看二进制文件
程序代码:
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<ctype.h> int main(int argc,char* argv[]) { if(argc!=2) { fprintf(stdout,"arguement error!\n"); exit(EXIT_FAILURE); } int count; char filename[FILENAME_MAX]; strcpy(filename,argv[1]); int len=strlen(filename); if(filename[len-1]=='\n') filename[len-1]='\0'; FILE* p=fopen(filename,"rb"); char buf[5*sizeof(char)]; setvbuf(p,NULL,_IOFBF,200); while(!feof(p)) { count=fread(buf,sizeof(char),5,p); for(int i=0;i<count;i++) fprintf(stdout,"%x ",buf[i]); fprintf(stdout,"| "); for(int i=0;i<count;i++) if(isprint(buf[i])) fprintf(stdout,"%c",buf[i]); else fprintf(stdout,"."); fprintf(stdout,"\n"); } fclose(p); }
[此贴子已经被作者于2018-1-22 07:17编辑过]