标签:style blog io ar color os sp for 文件
#include <stdio.h> int main(int argc, char *argv[]) { int i; FILE *fp = NULL; unsigned char *pData; int iLen, itmpLen, itmp; fp = fopen(argv[1], "rb"); if(fp == NULL) { printf("fopen err\n"); goto end; } fseek(fp, 0, SEEK_END); iLen = ftell(fp); if(iLen <= 0) { printf("file size err: %d\n", iLen); goto end; } printf("file size: %d\n", iLen); pData = malloc(iLen); if(pData == NULL) { printf("pData malloc err\n"); goto end; } //fseek(fp, 0, SEEK_SET); fclose(fp); fp = fopen(argv[1], "rb"); if(fp == NULL) { printf("fopen err\n"); goto end; } itmpLen = 0; while(itmpLen < iLen) { itmp = fread(pData+itmpLen, 1, iLen, fp); printf("itmp = %d\n", itmp); itmpLen += itmp; } for(i = 0; i < iLen; i++) { if(i != 0 && i % 16 == 0) printf("\n"); printf("0x%02x, ", pData[i]); } printf("\n"); fclose(fp); end: return 0; }
标签:style blog io ar color os sp for 文件
原文地址:http://www.cnblogs.com/utank/p/4147339.html