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 }

 

时间: 2024-10-10 04:37:41

Binary file to C array(bin2c)的相关文章

javac: cannot execute binary file

# java/jdk1.6.0_12/bin/javac-bash: java/jdk1.6.0_12/bin/javac: cannot execute binary file   后来检验,检查了一段时间,没有问题,最后有高人提示 经验证,是64位版本移到32位上.   http://www.cnblogs.com/quxuedan/archive/2012/08/22/2650497.html

android-/usr/bin/mkbootimg: cannot execute binary file

问题描述 /usr/bin/mkbootimg: cannot execute binary file 我用cygwin学习制作安卓recovery的编译,但是在打包的时候出现了/usr/bin/mkbootimg: cannot execute binary file问题,求助ing 解决方案 cannot execute binary fileerror: cannot execute binary file-bash: ./firstdrvtest: cannot execute bina

grep returns Binary file (standard input) matches

The grep -a, --text option may be of use to you. This will force grep to actually print the contents of the file. If you are looking to fix the actual file, I would say open it up in an editor and resave it and see what that does.

Linux下为何出现/java: cannot execute binary file

这种情况一般虚拟机的位数(32和64)不匹配造成的.重新下一个和你虚拟机匹配的JDK版本就行了 其中带有X64的都是64位,其他32位

30 个 PHP 的 Excel 处理类

下面的 PHP Excel 处理类中,包含 Excel 读写.导入导出等相关的类,列表如下: PHP Excel Reader classes 1 . Read Excel Spreadsheets using COM Umesh Rai (India) 2 . Read Excel Binary .XLS Files in Pure PHP Ruslan V. Uss (Russian Federation) 3 . Read Excel Spreadsheets using ODBC kha

Csharp:The .dat File using BinaryReader and BinaryWriter Convert to DataTable

/// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { BinaryWriter binWriter = new BinaryWriter(F

php file 函数

file ( PHP 4中, PHP 5中) file-读取整个file到一个数组 描述 一系列file(字符串$file[摘要$国旗= 0 [ ,资源$背景] ] ) 读取整个file到一个数组. 注:您可以使用file_get_contents ( )返回file内容作为一个字符串. 参数 file名 file路径. 提示 网址可以用来作为file名与此功能,如果打开包装已启用.见fopen ( )函数的更多细节关于如何指定file名和列表支持的协议/封装协议的列表,支持的URL协议. 旗帜

27.3. Directory and File System Related

27.3.1. dirname $ dirname /usr/bin/find /usr/bin 27.3.2. filename $ basename /usr/bin/find find 27.3.2.1. 排除扩展名 file=test.txt b=${file%.*} echo $b $ for file in *.JPG;do mv $file ${file%.*}.jpg;done 27.3.2.2. 取扩展名 file=test.txt b=${file##*.} echo $b

5.3. Directory and File System Related

5.3.1. dirname $ dirname /usr/bin/find /usr/bin 5.3.2. filename $ basename /usr/bin/find find 5.3.2.1. 排除扩展名 file=test.txt b=${file%.*} echo $b $ for file in *.JPG;do mv $file ${file%.*}.jpg;done 5.3.2.2. 取扩展名 file=test.txt b=${file##*.} echo $b 5.3.