30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Standard C Libraries with Math Functions<br />

2004 Microchip Technology Inc. DS51456B-page 253<br />

printf<br />

Description: Prints formatted text to stdout.<br />

Include: <br />

Prototype: int printf(const char *format, ...);<br />

Arguments: format format control string<br />

... optional arguments<br />

Return Value: Returns number of characters generated or a negative number if<br />

an<br />

error occurs.<br />

Remarks: There must be exactly the same number of arguments as there are<br />

format specifiers. If the are less arguments than match the format<br />

specifiers, the output is undefined. If there are more arguments than<br />

match the format specifiers, the remaining arguments are discarded.<br />

Each format specifier begins with a percent sign followed by optional<br />

fields and a required type as shown here:<br />

%[flags][width][.precision][size]type<br />

flags<br />

- left-justify the value within a given field width<br />

0 Use 0 for the pad character instead of space (which is the<br />

default)<br />

+ generate a plus sign for positive signed values<br />

space generate a space or signed values that have neither a plus<br />

nor a minus sign<br />

# to prefix 0 on an octal conversion, to prefix 0x or 0X on a<br />

hexadecimal conversion, or to generate a decimal point<br />

and fraction digits that are otherwise suppressed on a<br />

floating-point conversion<br />

width<br />

specify the number of characters to generate for the conversion. If<br />

the asterisk (*) is used instead of a decimal number, the next<br />

argument (which must be of type int) will be used for the field<br />

width. If the result is less than the field width, pad characters will be<br />

used on the left to fill the field. If the result is greater than the field<br />

width, the field is expanded toaccommodate the value without<br />

padding.<br />

precision<br />

The field width can be followed with dot (.) and a decimal integer<br />

putc<br />

Mô tả: Đặt một ký tự dòng.<br />

Bao gồm:<br />

Nguyên mẫu: int putc (int c, FILE * stream);<br />

Đối số: ký tự c được viết<br />

dòng con trỏ đến cấu trúc FILE<br />

Quay trở lại giá trị: Trả về nhân vật hoặc EOF nếu lỗi xảy ra hoặc kết thúc của<br />

tập tin<br />

đạt được.<br />

Bình luận: putcis giống như chức năng fputc.<br />

Ví dụ: # include / * Cho putc, kết thúc tập tin, thiết bị xuất chuẩn * /<br />

int main (void)<br />

{<br />

char * y;<br />

char buf [] = "Đây là văn bản \ n";<br />

int x;<br />

x = 0;<br />

cho (y = buf; (x = EOF) && (* y = '\ 0');! y ++!)<br />

{<br />

x = putc (* y, thiết bị xuất chuẩn);<br />

putc ('|', thiết bị xuất chuẩn);<br />

}<br />

}<br />

Đầu ra:<br />

T | h | i | s | | i | s | | t | e | x | t |<br />

|<br />

printf (Tiếp theo)<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 256<br />

putchar<br />

2004 Microchip Technology Inc<br />

Mô tả: Đặt một nhân vật để thiết bị xuất chuẩn.<br />

Bao gồm:<br />

Nguyên mẫu: int putchar (int c);<br />

Đối số: ký tự c được viết<br />

Quay trở lại giá trị: Trả về nhân vật hoặc EOF nếu lỗi xảy ra hoặc kết thúc của<br />

tập tin<br />

đạt được.<br />

Bình luận: cùng tác dụng như fputcwith stdoutas một cuộc tranh cãi.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!