2013-11-28 66 views
0

我正在嘗試使用printf打印%符號。C:使用printf打印%符號

我都試過,沒有運氣:

printf("\%"); 

我敢肯定,它很簡單,但我剛開始C.

感謝。

+3

這是''%%。 [閱讀手冊](http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html)。 – netcoder

+1

相關:[爲什麼百分比字符不用C中的反斜槓轉義?](http://stackoverflow.com/questions/17811531/why-is-percentage-character-not-escaped-with-backslash-in-c)(雖然不一定重複) – Kninnug

回答

3

使用printf("%%");反斜槓是C字符串轉義字符使用;編譯器解釋它。百分號是printf s轉義字符; printf例程解釋它。

+1

謝謝,非常感謝。 – mitchellt

3

嘗試使用以下轉義序列:

%%

檢查所有escapes*rintf()系列函數

+2

謝謝,感謝。 – mitchellt

2

這裏有兩種方法:

printf("%%\n"); 
printf("%c\n", '%'); 
+0

第二個並不是真的有必要。這可能比第一個慢。 –

+1

@TheMask有很多方法可以做同樣的事情...只是試圖證明,以mitchellt –

+1

謝謝,欣賞它。 – mitchellt