Binary file to C array

 1 /********************************************************************************
 2  *                          Binary file to C array
 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-08-30 09:50:53

Binary file to C array的相关文章

【转】 grep 文件报错 “Binary file ... matches”

原文链接 http://blog.csdn.net/yaochunnian/article/details/7261006 grep 文件报错 “Binary file ... matches” 原因:文件为binary文件 解决:strings vers.log.2010-03-09 | grep -i ‘mezimedia’ 或者 grep -a -i ‘mezimedia’ vers.log.2010-03-09 grep命令是linux下的行过滤工具,其参数繁多,下面就一一介绍个个参数的

【开发环境】 uClinux内核编译问题&lt;config/kconfig/mconf: cannot execute binary file&gt;问题解决方法

一.前言 最近进行uClinux移植,make menuconfig时碰到如下问题: [[email protected] uClinux-dist]$ make menuconfig find vendors -mindepth 2 '(' -name .svn -prune ')' -o -type f -name Kconfig -print | sed 's:^:source ../:' > vendors/Kconfig config/mkconfig > Kconfig KCONF

-bash: /root/java/jdk/bin/java: cannot execute binary file

错误 -bash: /root/java/jdk/bin/java: cannot execute binary file 错误原因 安装的Linux的版本是32位的,下载的软件是64位,版本不兼容,需要换一个相同位数的版本 查看Linux的版本 file  /sbin/init 或者  file /bin/ls 这个显示你的版本是32位的 反之则是64位的

centos7下安装nmon后,无法运行,提示 cannot execute binary file或/lib64/ld64.so.1不存在

在centos 7.1上安装nmon后,从管网(http://nmon.sourceforge.net/pmwiki.php?n=Site.Download)下载tar包解压后,两台机器一台提示 cannot execute binary file,另一台提示/lib64/ld64.so.1不存在 找了好久都没找到解决方法,换rpm安装方式解决 rpm 下载地址 http://rpm.pbone.net/index.php3/stat/4/idpl/29435642/dir/redhat_el_

What is a text file and what is a binary file :)

If you are not coming from a programming background it might not yet be clear what is really a file? What is a binary file and what makes something a text file? 其实总归一句话:[Files that consist exclusively of ASCII characters are known as text ?les. All o

解决:cannot execute binary file

linux系统下遇到cannot execute binary file的问题,一般由以下情况造成: 非root用户或者无执行权限 编译环境不同(程序由其他操作环境复制过来) 对于第一种情况,采用增加执行权限即可chmod +x program 对于第二种情况,建议将该程序二进制包拷贝过来,重新编译程序.因为我在实际操作过程中发现我将美国的VPS的整个操作系统环境打包后下载到本地服务器上解压后运行其中的程序会有如题所示问题出现,百思不得其解,系统都为centos5.2,最终发现是两者编译环境不同

Linux下出现/java: cannot execute binary file

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

grep:Binary file (standard input) matches

grep "key" xxx.log时输出 Binary file xxx.log matches 百度了一下:grep认为这是二进制文件,解决方案:grep -a. grep -a "key" xxx.log

linux运行run文件显示cannot execute binary file

需要检查一下这个文件是否 shell 脚本, 如果是shell脚本, 才可以使用 "sh ***.run"的形式执行. 如果本身是一个可执行的命令程序, 不需要使用 sh, 直接加上执行权限, 执行这个应用程序就可以 (类似 windows下的 .exe文件 ) 如果不是shell脚本 1. file 文件名 可以查看文件类型; 2. 或者: more 文件名 查看文件内容是否可读文本 3. 修改权限 chmod 777 文件名 或者: chmod a+x 文件名 如果没有权限, 需要