Skip to content

Instantly share code, notes, and snippets.

@FilippoBiga
Created April 17, 2011 19:33
Show Gist options
  • Save FilippoBiga/924398 to your computer and use it in GitHub Desktop.
Save FilippoBiga/924398 to your computer and use it in GitHub Desktop.
generat a char[] from a string
#!/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