如何在c中'\ n'之后定义空格数

时间:2017-11-24 07:27:50

标签: c

我想打印一下:

    printf("please Choose: 1-For Checking what is the most popular number in the array\n               2-To sort your array from the smallest number to the biggest\n               3-To sort your array that even will be to your left and odd to the right\n               *Any other number will exit the program\n");

有一种方法可以在'\ n'之后定义空格数而不是输入大量的空格吗?

1 个答案:

答案 0 :(得分:3)

尝试:

printf("%Ns\n", "");

其中N是您要显示的空格数。

这样您就会显示一个以N空格开头的空字符串。

printf("please Choose: 1-For Checking what is the most popular number in the array\n%8s2-To sort your array from the smallest number to the biggest\n%8s3-To sort your array that even will be to your left and odd to the right\n%8s*Any other number will exit the program\n", "", "", "");