Reputation: 1
I like including ASCII art in my projects and until now I used to print it like this:
printf (R "EOF(
* MMM8&&& *
MMMM88&&&&& .
MMMM88&&&&&&&
* MMM88&&&&&&&&
MMM88&&&&&&&&
MMM88&&&&&&
MMM8&&& *
|\___/|
=) ^Y^ (= . '
\ ^ /
)=*=( *
/ \
| |
/| | | |\
\| | |_|/\
_/\_//_// ___/\_/\_/\_/\_/\_/\_/\_
| | | | \_) | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
| | | | | | | | | | | |
)EOF");
is there an alternative as easy to use as this for C?
Upvotes: 0
Views: 16190
Reputation: 1
Just use literal strings. Of course, you'll need to encode some characters (notably quotes, double quotes, backslashes, newlines, etc...).
puts(
" * MMM8&&& *\n"
" MMMM88&&&&& .\n"
" MMMM88&&&&&&&\n"
and so on. Remember that puts is appending a final newline (you don't want to use printf, because some characters, notably %
, have a special role, and because it is probably slower). If you don't want that final newline, consider also fputs.
In C and C++, two (or more) string literals are assembled in one.
BTW, you could also generate such C code, or perhaps have something which transforms any file (e.g. your ASCII art) into an initialization like
const char data[] = { 0x20,
etc...
Upvotes: 4