In C can a long printf statement be broken up into multiple lines?

neuromancer picture neuromancer · Nov 17, 2009 · Viewed 128k times · Source

I have the following statement:

printf("name: %s\targs: %s\tvalue %d\tarraysize %d\n", sp->name, sp->args, sp->value, sp->arraysize);

I want to break it up. I tried the following but it doesn't work.

printf("name: %s\t
args: %s\t
value %d\t
arraysize %d\n", 
sp->name, 
sp->args, 
sp->value, 
sp->arraysize);

How can I break it up?

Answer

James McNellis picture James McNellis · Nov 17, 2009

If you want to break a string literal onto multiple lines, you can concatenate multiple strings together, one on each line, like so:

printf("name: %s\t"
"args: %s\t"
"value %d\t"
"arraysize %d\n", 
sp->name, 
sp->args, 
sp->value, 
sp->arraysize);