jake929 jake929 - 1 month ago 7
C Question

How to format/indent multiple line text constants

How do I use one print function to print all the text with correct code indentation on the second and subsequent lines?

printf("Program information\nThe program reads in the number of judges and \
the score from each judge.\nThen it calculates the average score without \
regard to the lowest and\nhighest judge score. Finally it prints the \
results (the highest, the \nlowest and the final average score).\n\n");

Answer

You want to avoid using \[newline] inside string constants.

The c compiler will concatenate string constants for you, so you can format it like this:

printf("Program information\n"
       "The program reads in the number of judges and the score from each judge.\n"
       "Then it calculates the average score without regard to the lowest and\n"
       "highest judge score. Finally it prints the results (the highest, the \n"
       "lowest and the final average score).\n\n");