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.

else<br />

printf("Cannot allocate memory\n");<br />

}<br />

Output:<br />

i[0] = 0<br />

i[1] = 0<br />

i[2] = 0<br />

i[3] = 0<br />

i[4] = 0<br />

div<br />

Description: Calculates the quotient and remainder of two numbers<br />

Include: <br />

Prototype: div_t div(int numer, int denom);<br />

Arguments: numer numerator<br />

denom denominator<br />

Return Value: Returns the quotient and the remainder.<br />

Remarks: The returned quotient will have the same sign as the numerator<br />

divided<br />

by the denominator. The sign for the remainder will be such that the<br />

quotient times the denominator plus the remainder will equal the<br />

numerator (quot * denom + rem = numer). Division by zero will invoke<br />

the math exception error, which by default, will cause a reset. Write a<br />

math error handler todo something else.<br />

Standard C Libraries with Math Functions<br />

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

Example: #include /* for div, div_t */<br />

#include /* forprintf */<br />

void __attribute__((__interrupt__))<br />

_MathError(void)<br />

{<br />

printf("Illegal instruction executed\n");<br />

abort();<br />

}<br />

int main(void)<br />

{<br />

int x, y;<br />

div_t z;<br />

x = 7;<br />

y = 3;<br />

if ((i = (long *) malloc (50 * sizeof (long))) ==<br />

NULL)<br />

printf ("Không thể cấp phát bộ nhớ \ n");<br />

khác<br />

{<br />

printf ("bộ nhớ phân bổ \ n");<br />

miễn phí (i);<br />

printf ("giải phóng bộ nhớ \ n");<br />

}<br />

}<br />

Đầu ra:<br />

Cấp phát bộ nhớ<br />

Bộ nhớ giải phóng<br />

getenv<br />

Mô tả: Lấy một giá trị cho một biến môi trường.<br />

Bao gồm:<br />

Prototype: char * getenv (const char * name);<br />

Tên tên của biến môi trường: Đối số<br />

Quay trở lại giá trị: Trả về một con trỏ đến giá trị của biến môi trường nếu thàn<br />

công;<br />

nếu không, trả về một con trỏ null.<br />

Bình luận: Chức năng này phải được tùy chỉnh để được sử dụng như mô tả (xem<br />

pic30-libs). Theo mặc định không có mục trong danh sách môi trường<br />

cho getenvto tìm.<br />

dsPIC<br />

®<br />

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

DS51456B trang 282<br />

2004 Microchip Technology Inc<br />

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

# include / * Cho getenv * /<br />

int main (void)<br />

{<br />

char * incvar;<br />

incvar = getenv ("BAO GỒM");<br />

if (incvar! = NULL)<br />

printf ("BAO GỒM biến môi trường =% s \ n",<br />

incvar);<br />

khác<br />

printf ("Không thể tìm thấy biến môi trường"<br />

"BAO GỒM");

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

Saved successfully!

Ooh no, something went wrong!