Skip to content

Instantly share code, notes, and snippets.

@jarekt
Created July 25, 2019 15:10
Show Gist options
  • Save jarekt/40673b314cf20a14c91e92bcbaf7d5d3 to your computer and use it in GitHub Desktop.
Save jarekt/40673b314cf20a14c91e92bcbaf7d5d3 to your computer and use it in GitHub Desktop.
simple script for converting a file into an includable header file (in the form of a const char array) for your c / cpp programs
#this script takes a file and makes it into a c string in a header file
file_name = "tetris.ch8"
newfile_name = "tetris.h"
start_string = '#define LOAD_STRING\nconst char import_string[] = {'
end_string = '};'
oldFile = open(file_name, "rb")
oldFile = oldFile.read()
oldFile = "".join( hex(x) +"," for x in oldFile)
oldFile = start_string + oldFile + end_string
newFile = open(newfile_name, "wt")
newFile.write(oldFile)
newFile.close()
print(oldFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment