我正在打印一系列線條。線條的長度是不同的。有時我必須在線條的末端添加空格以對齊線條。並且在每行的末尾添加「\ 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