keil C51:printf sprintf vprintf vsprintf 函數學習

來源:互聯網
上載者:User

在keil安裝目錄,其中有STDIO.H 其中有幾個print函數如下:

extern int printf   (const char *, ...);extern int sprintf  (char *, const char *, ...);extern int vprintf  (const char *, char *);extern int vsprintf (char *, const char *, char *);

vprintf對應printf,將資料以ascii碼的形式列印到串口

vsprintf 對應sprintf,將資料以ascii碼的形式列印到buffer中。


The sprintf function formats a series of strings and numeric values and stores the resulting string in buffer. 

This function is similar to the printf routine, but it stores the formatted output in buffer rather than sending it to the output stream.

printf的原理是從 “字元指標變數”(單位元組指標)開始從串口發送出,如果遇到‘\0’(0x00)就停止發送,注意這個0x00是不會發送的。


buffer[0]=0x00;buffer[2]=0x00;//buffer[2]=0x01; TI = 1;ES = 0;printf(buffer);ES = 1;


這樣子是不會發送任何資料的,因為buffer指向的第一個位元組的資料是0x00,那麼就不會發送資料。

但是如果buffer[0]是一個非0x00的資料,那麼就可以送,但是buffer[1]預設沒有初始化,所以只發送第一個資料。

所以如果要發送一個數組,其中包括0x00,那麼就不能用printf函數。要用一個for迴圈來發送資料遍曆整個數組。



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.