如何format/indent 多行文本常量
How to format/indent multiple line text constants
如何使用一个打印功能在第二行和后续行上以正确的代码缩进打印所有文本?
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");
如之前删除的答案中的评论所示,我认为您需要 \t
缩进。
这是基本制表符。
所以可能是这样:
printf("Program information\nThe program reads in the number of judges and \
the score from each judge.\n\tThen it calculates the average score without \
regard to the lowest and\n\thighest judge score. Finally it prints the \
results (the highest, the \n\tlowest and the final average score).\n\n");
您想避免在字符串常量中使用 \[newline]
。
C 编译器会为您连接字符串常量,因此您可以这样格式化:
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");
如何使用一个打印功能在第二行和后续行上以正确的代码缩进打印所有文本?
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");
如之前删除的答案中的评论所示,我认为您需要 \t
缩进。
这是基本制表符。
所以可能是这样:
printf("Program information\nThe program reads in the number of judges and \
the score from each judge.\n\tThen it calculates the average score without \
regard to the lowest and\n\thighest judge score. Finally it prints the \
results (the highest, the \n\tlowest and the final average score).\n\n");
您想避免在字符串常量中使用 \[newline]
。
C 编译器会为您连接字符串常量,因此您可以这样格式化:
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");