Skip to content

Instantly share code, notes, and snippets.

@qeedquan
Created July 16, 2017 17:42
Show Gist options
  • Save qeedquan/af7d62dd65c6b3c4394f83e813726248 to your computer and use it in GitHub Desktop.
Save qeedquan/af7d62dd65c6b3c4394f83e813726248 to your computer and use it in GitHub Desktop.
Using macro to create a multiline string
// how to do make a string out of multiple lines
// using the preprocessor
#include <stdio.h>
#define STRINGIFY(...) #__VA_ARGS__
int
main(void)
{
char *s = STRINGIFY(
she walked by the shore
staring into the stars.
\n\n\b
testify brother; for ye
shall receive covfefe punishment.
\n\n\b
1, 2, 3, 4
\n\n\b
kidz war in the trenches,
not a sight to behold.
\n\n\b
"add some string so i can\
subtract some doubt \
or not"
\n\n\b
#define A(x) MEH
A(10)
// include gets precedence, it will expand first then stringify
// uncomment to see
// #include <stdio.h>
\n\n\b
the end.
);
printf("%s\n", s);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment