#include "stdio.h"
int main()
{
int toes = 10;
printf("toes=%d\t2toes=%d\ttoes2=%d\n",toes,toes+toes,toes*toes);
return 0;
}
//这是来自c primer plus的练习。编译并运行后,只有第二个\ t工作。为什么第一个 t不起作用?
#include "stdio.h"
int main()
{
int toes = 10;
printf("toes=%d\t2toes=%d\ttoes2=%d\n",toes,toes+toes,toes*toes);
return 0;
}
//这是来自c primer plus的练习。编译并运行后,只有第二个\ t工作。为什么第一个 t不起作用?
选项卡将文本缩进到固定位置。这意味着,他们不会造成4空格的差距,但会在匹配下一个标记的位置之前留下空隙。
toes=10 2toes=20 toes2=100
1234567812345678123456781234567812345678
这是一个不幸的例子。您的标签长8。所以他们停止每8个字母。如果您在第一个\t
之前添加了一个空格,那么您的选项卡会造成更大的差距。
printf("%s%s%s\n", " single", " double", " square");
printf("%7d%7d%7d\n", toes, 2*toes, toes*toes);
输出::
single double square
10 20 100
甲\t
字符将不总是采取相同的空间,这将调整到列
更好的输出格式将由来实现。
如果您希望在条目之间有固定数量的空格,请在值之间手动输入它们。
它正在工作,但它似乎不是!
这是因为默认情况下,您有一个tabspace
等于8
spaces
。并且toes=10
占用了7
的空间,并且只有1
的空间,如果留给\t
来填充。
要看到,它正在改变你的printf
到:
printf("ts=%d\t2toes=%d\ttoes2=%d\n",toes,toes+toes,toes*toes);
你是什么意思与_ \ t不与WORK_? – pzaenger
它可以工作,但在视觉表示中不会占用一个以上的空间?尝试通过hexdump运行它,或将其复制并粘贴到编辑器,其中有空白字符的特殊可视化。 – moooeeeep
选项卡不会插入x空格。它将输出与控制台窗口中的列对齐。 –