import os
import sys
from struct import *
#把c数组类型的文件转成2进制文件
#
def c_arrar_to_bin(c_txt_file,bin_file):
myfile = open(c_txt_file,'r')
outfile = open(bin_file,'wb')
result = ''
for line in myfile:
newstr = line
outstr = ''
while newstr.find("0x")>=0:
pos=newstr.find("0x")
b= int(newstr[pos+2:pos+4],16) #把字符转成16进制
result += pack('B',b) #保存
newstr = newstr[pos+1:] #删除前面的字符
outfile.write(result)
outfile.close()
myfile.close()
print '---start---'
c_arrar_to_bin('c:\c_tpye.txt', 'c:\c_tpye.bin')
print '----end----'