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.

printf("Favorite number = %d, ", number);<br />

printf("Favorite letter = %c\n", letter);<br />

printf("Favorite color= %s, ", color);<br />

printf("Desired salary = $%.2f\n", salary);<br />

printf("Social Security Number = %s, ", string);<br />

}<br />

Input:<br />

Contents of UartIn.txt(used as stdin input for simulator):<br />

5 T Green 300000 123-45-6789<br />

Output:<br />

Enter your favorite number, favorite letter,<br />

favorite color, desired salary and SSN:<br />

Number of items scanned = 5<br />

Favorite number = 5,Favorite letter = T<br />

Favorite color = Green, Desired salary = $300000.00<br />

Social Security Number = 123-45-6789<br />

scanf (Continued)<br />

Standard C Libraries with Math Functions<br />

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

setbuf<br />

Description: Defines how a stream is buffered.<br />

Include: <br />

Prototype: void setbuf(FILE *stream, char *buf);<br />

Arguments: stream pointer to the open stream<br />

buf user allocated buffer<br />

Remarks: setbufmust be called after fopenbut before any other function calls<br />

that operate on the stream. If bufis a null pointer, setbufcalls the<br />

function setvbuf(stream, 0, _IONBF, BUFSIZ)for no buffering;<br />

otherwise setbufcalls setvbuf(stream, buf, _IOFBF,<br />

BUFSIZ)for full buffering with a buffer of size BUFSIZ. See setvbuf.<br />

Example: #include /* for setbuf, printf, */<br />

/* fopen, fclose, */<br />

/* FILE, NULL, BUFSIZ */<br />

int main(void)<br />

{<br />

FILE *myfile1, *myfile2;<br />

char buf[BUFSIZ];<br />

if ((myfile1 = fopen("afile1", "w+")) != NULL)<br />

{<br />

}<br />

Đầu ra:<br />

Số ký tự được in chuỗi đệm = 25<br />

String = In trang nay chuỗi 1 lần<br />

sscanf<br />

Mô tả: Quét định dạng văn bản từ một chuỗi<br />

Bao gồm:<br />

Nguyên mẫu: int sscanf (const char * s, char * format, ...);<br />

Đối số: s chuỗi lưu trữ cho các định dạng đầu vào chuỗi kiểm soát định dạng<br />

Đối số tùy chọn ...<br />

Quay trở lại giá trị: Trả về số lượng các mục chuyển đổi thành công và được<br />

giao. Nếu<br />

Không có sản phẩm được giao, một 0 được trả về. Kết thúc tập tin được trả lại<br />

nếu một lỗi đầu vào<br />

đang gặp phải trước khi chuyển đổi đầu tiên.<br />

Ghi chú: Đối số định dạng có cú pháp tương tự và sử dụng nó có trong<br />

scanf.<br />

dsPIC<br />

®<br />

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

DS51456B trang 264<br />

2004 Microchip Technology Inc<br />

Ví dụ: # include / * Cho sscanf, printf * /<br />

int main (void)<br />

{<br />

char s [] = "5 T 3.000.000,00 xanh";<br />

int số lượng, mặt hàng;<br />

thư char;<br />

char màu [10];<br />

nổi tiền lương;<br />

mục = sscanf (s, "% d% c% s% f", & số, và lá thư,<br />

Và màu sắc, và tiền lương);<br />

printf ("Số scan =% d \ n", các mục);<br />

printf ("yêu thích số =% d \ n", số lượng);<br />

printf ("thư yêu thích =% c \ n", thư);<br />

printf ("Màu sắc ưa thích =% s \ n", màu sắc);<br />

printf ("lương Desired = $% 2f. \ n", tiền lương);<br />

}<br />

Đầu ra:<br />

Số mục quét = 4<br />

Số yêu thích = 5

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

Saved successfully!

Ooh no, something went wrong!