使用printf輸出

2021-06-16 02:24:58 字數 513 閱讀 6200

echo命令的不同版本導致了unix系列機移植性最為頭痛的事情,在posix第一輪標準化時,委員會委員就如何標準化echo沒有達成一致意見,所以他們想出了乙個妥協的方案。echo是posix 標準的一部分,但是標準並不詳盡的指明echo的第乙個引數的具體行為。

printf命令能夠像echo命令一樣輸出簡單的字串:

printf "hello, world/n"

主要不同之處在於不像echo,printf 不自動支援換行,你必須清楚指出'/n'。完整的printf語法有兩個部分:

printf format-string

[arguments ...

]乙個部分是你想輸出的字串。另外一部分是引數列表,例如字串或變數值。

$printf "the first program always prints '%s, %s!'/n" hello worldthe first program always prints 'hello, world!'

使用printf向串列埠輸出資料

引自 要在iar中使用printf向串列埠輸出資料,需要加入如下的函式原型,它的目的是將printf指向串列埠一這個裝置並向這個裝置輸出資料。ifdef gnuc with gcc raisonance,small printf option ld linker libraries small pr...

STVD使用printf輸出資料錯誤

使用stm8l052輸出除錯資訊 重定向put char include stdio.h 必不可缺少 char putchar char c 輸出字串都沒問題。typedef struct sysparam sysparam sys 定義了乙個結構體資料 printf hello world 當我輸...

Printf格式輸出

printf 輸出各種型別 完整格式 0m.nl或者h格式字元 轉換說明的開始 佔位符 不能省略 左對齊,省略 右對齊 0 有0代表空位填0,省略代表空位不填 m.n m域寬 指對應的輸出項在輸出裝置占用多個字元的寬度 n精度 輸出浮點數的時候 小數點後面的位數 l 整數long浮點數double ...