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.

i = -2;<br />

printf("The absolute value of %d is %d\n",<br />

i, abs(i));<br />

i = 0;<br />

printf("The absolute value of %d is %d\n",<br />

i, abs(i));<br />

}<br />

Output:<br />

The absolute value of 12 is 12<br />

The absolute value of -2 is 2<br />

The absolute value of 0 is 0<br />

atexit<br />

Description: Registers the specified function to be called when the program<br />

terminates normally.<br />

Include: <br />

Prototype: int atexit(void(*func)(void));<br />

Argument: func function to be called<br />

Return Value: Returns a zero if successful; otherwise, returns a non-zero value.<br />

Remarks: For the registered functions to be called, the program must terminate<br />

with the exitfunction call.<br />

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

#include /* for atexit, exit */<br />

void good_msg(void);<br />

void bad_msg(void);<br />

void end_msg(void);<br />

Standard C Libraries with Math Functions<br />

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

int main(void)<br />

{<br />

int number;<br />

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

int main (void)<br />

{<br />

char a [] = "-127";<br />

char b [] = "Number1";<br />

int x;<br />

x = atoi (a);<br />

printf ("String = \"% s \ "\ màu =% d \ n", a, x);<br />

x = atoi (b);<br />

printf ("String = \"% s \ "\ màu =% d \ n", b, x);<br />

}<br />

Đầu ra:<br />

String = "-127" int = -127<br />

String = "Number1" int = 0<br />

atol<br />

Mô tả: Chuyển đổi một chuỗi thành một số nguyên dài.<br />

Bao gồm:<br />

Prototype: atol dài (const char * s);<br />

Đối số: s chuỗi được chuyển đổi<br />

Quay trở lại giá trị: Trả về longinteger chuyển đổi nếu thành công; nếu không,<br />

trả về 0<br />

Ghi chú: Số lượng có thể bao gồm những điều sau đây:<br />

[Khoảng trắng] [dấu hiệu] chữ số<br />

khoảng trắng tùy chọn, theo sau là một signthen tùy chọn một chuỗi<br />

của một hoặc nhiều chữ số. Việc chuyển đổi dừng lại khi lần đầu tiên<br />

nhân vật không được công nhận là đạt. Việc chuyển đổi tương đương với<br />

(Int) strtol (s, 0,10), ngoại trừ nó không có kiểm tra lỗi để errno<br />

sẽ không được thiết lập.<br />

dsPIC<br />

®<br />

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

atexit(end_msg);<br />

DS51456B trang 276<br />

2004 Microchip Technology Inc<br />

printf("Enter your favorite number:");<br />

scanf("%d", &number);<br />

printf(" %d\n", number);<br />

if (number == 5)<br />

{<br />

printf("Good Choice\n");<br />

atexit(good_msg);<br />

exit(0);<br />

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

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

int main (void)<br />

{<br />

char a [] = "-123.456";<br />

char b [] = "2Number";<br />

x dài;<br />

x = atol (a);

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

Saved successfully!

Ooh no, something went wrong!