Binary file to C array(bin2c)

简介: 1 /******************************************************************************** 2 * Binary file to C array(bin2c) ...
 1 /********************************************************************************
 2  *                          Binary file to C array(bin2c)
 3  *  说明:
 4  *      由于工作中需要将bmp文件数据转换成C数组,于是写了这个工具(bin2c),代码如你
 5  *      所见,只有看上去不多的几行.
 6  *
 7  *                                2015-4-20 周一 阴 深圳 南山 西丽平山村 曾剑锋
 8  *******************************************************************************/
 9 #include <stdio.h>
10 #include <string.h>
11 
12 int main ( int argc, char** argv )
13 {
14     int i = 0;            
15     char ch = '\0';        
16 
17     if ( 2 != argc ) {
18         printf( "\n    Usage: bin2c <file> \n\n" );
19         return -1;
20     }
21 
22     FILE *binfile = fopen( argv[1], "rb" );
23 
24     // get file name for array's name
25     while ( '.' != argv[1][i++] );
26     argv[1][ i-1 ] = 0;
27 
28     //get file data and change to const unsigned char array's data
29     i = 1;
30     printf( "const unsigned char %s[] = { \n\t", argv[1] );
31     while ( EOF != (ch = fgetc( binfile )) ) 
32          printf( "0x%02X%s\t", (unsigned char)ch , ( i++ % 8 ) == 0 ? "\n" : "" );
33     printf( "\n};\n" );
34 
35     fclose( binfile );
36 }

 

目录
相关文章
E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: 没有那个文件或目录)
E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: 没有那个文件或目录)
155 0
|
8月前
|
缓存 前端开发 PHP
PHP - Laravel The stream or file “/storage/logs/.“ could not be opened in append
PHP - Laravel The stream or file “/storage/logs/.“ could not be opened in append
343 0
|
10月前
|
分布式计算 Hadoop 程序员
ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
ERROR util.Shell: Failed to locate the winutils binary in the hadoop binary path
|
PyTorch 算法框架/工具
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument
121 0
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=405 error=11 : invalid argument