Created
July 25, 2019 15:10
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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