我正在打印一系列线条。线条的长度是不同的。有时我必须在线条的末端添加空格以对齐线条。并且在每行的末尾添加“\ n”字符。问题在于“\ n”后面的新行似乎在下一行的一些空格后面开始。它很奇怪。任何建议或意见表示赞赏。c printf漂亮打印格式
switch(struct.var1) {
case 0:
switch(struct.var2)
{
case 1: printf("xyx");break;
case 2: printf("abc");break;
}
break;
case 2: printf("xyz");break;
case 3: printf("xyz");break;
.
.
.
.
.
.
.
.
.
.
.
.
.
.
case n: printf("XYZ ");break;
case m:printf("ABC ");break;
case 0xff:
switch(struct.var2)
{
case 1: printf("MNO ");
case 2: printf("QRS ");
}
}//end of switch case.
printf("\n");
请找到上面的代码片段。这显然是printf的对齐问题。我无法真正发现代码的任何问题。
我们可以看到一些代码吗? – emboss
你可以发布打印,预期输出和实际输出的代码片段吗? –
开关(struct.var1){ 情况下0: \t开关(struct.var2) \t { \t壳体1:输出( “XYX”);打破; \t案例2:printf(“abc”); break; \t} \t break; \t案例2:printf(“xyz”); break;案例3:printf(“xyz”); break; \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t。 \t case n:printf(“XYZ”); break; \t case m:printf(“ABC”); break; \t 0xff的情况下: \t开关(struct.var2) \t { \t \t壳体1:输出( “MNO”); \t \t案例2:printf(“QRS”); \t} \t} //结束切换案例。 \t printf(“\ n”); – liv2hak