30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

10.0/2 = 5.000000<br />

10.0/3 = 3.333333<br />

10.0/4 = 2.500000<br />

10.0/5 = 2.000000<br />

10.0/6 = 1.666667<br />

10.0/7 = 1.428571<br />

10.0/8 = 1.250000<br />

10.0/9 = 1.111111<br />

10.0/10 = 1.000000<br />

Wrote 10 numbers<br />

Read 10 numbers<br />

1 * 10.000000 = 10.000000<br />

2 * 5.000000 = 10.000000<br />

3 * 3.333333 = 10.000000<br />

4 * 2.500000 = 10.000000<br />

5 * 2.000000 = 10.000000<br />

6 * 1.666667 = 10.000000<br />

7 * 1.428571 = 10.000000<br />

8 * 1.250000 = 10.000000<br />

9 * 1.111111 = 10.000000<br />

10 * 1.000000 = 10.000000<br />

Explanation:<br />

This program uses fwriteto save 10 numbers to a file in binary form.<br />

This allows the numbers to be saved inthe same pattern of bits as the<br />

program is using which provides more accuracy and consistency. Using<br />

fprintfwould save the numbers as textstrings, which could cause<br />

the numbers to be truncated. Eachnumber is divided into 10 to<br />

produce a variety of numbers. Retrieving the numbers with freadto a<br />

new array and multiplying them by the original number shows the<br />

numbers were not truncated in the save process.<br />

fwrite (Continued)<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

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

getc<br />

Description: Get a character from the stream.<br />

Include: <br />

Prototype: int getc(FILE *stream);<br />

Đầu vào:<br />

Nội dung UartIn.txt (được sử dụng như là đầu vào thiết bị nhập chuẩn cho mô<br />

phỏng):<br />

Ngắn<br />

Chuỗi dài hơn<br />

Đầu ra:<br />

Tiêu đề: Ngắn<br />

perror<br />

Mô tả: In một thông báo lỗi để thiết bị lỗi chuẩn.<br />

Bao gồm:<br />

Prototype: void perror (const char * s);<br />

Đối số: s chuỗi in<br />

Quay trở lại giá trị: Không có.<br />

Ghi chú: Các chuỗi s được in theo sau dấu hai chấm và một không gian. Sau đó<br />

một lỗi<br />

tin dựa trên errnois được in theo sau là một dòng mới<br />

Ví dụ: # include / * Cho perror, fopen, * /<br />

/ * Fclose, printf, * /<br />

/ * FILE, NULL * /<br />

int main (void)<br />

{<br />

FILE * myfile;<br />

if ((myfile = fopen ("samp.fil", "r +")) == NULL)<br />

perror ("Không thể mở samp.fil");<br />

khác<br />

printf ("Thành công mở samp.fil \ n");<br />

fclose (myfile);<br />

}<br />

Đầu ra:<br />

Không thể mở samp.fil: tập tin lỗi mở<br />

được (Tiếp theo)<br />

Thư viện chuẩn C với hàm toán học<br />

2004 Microchip Technology Inc DS51456B trang 253<br />

printf<br />

Mô tả: In định dạng văn bản để thiết bị xuất chuẩn.<br />

Bao gồm:<br />

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

Đối số: chuỗi định dạng kiểm soát định dạng<br />

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

Quay trở lại giá trị: Trả về số ký tự được tạo ra hoặc một số âm nếu một

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

Saved successfully!

Ooh no, something went wrong!