Created
April 17, 2011 19:33
-
-
Save FilippoBiga/924398 to your computer and use it in GitHub Desktop.
generat a char[] from a string
This file contains hidden or 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
#!/bin/sh | |
# Usage: CharGen.sh charname "string" | |
cprint() { printf "$charname[$ccount]='$1'; " | sed 's/_/\ /g'; } | |
string=`echo "$2" | sed 's/ /_/g'` | |
charname="$1" | |
ccount=`echo $string | fold -w1 | wc -l | sed 's/\ //g'` | |
printf "$charname[$ccount];\n" | |
ccount=0 | |
for character in `echo $string | fold -w1`; do cprint $character; let ccount++; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment