neuromancer neuromancer - 3 months ago 13
C Question

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

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

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);