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.

Standard C Libraries with Math Functions<br />

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

strtol<br />

Description: Converts a partial string to a long integer.<br />

Include: <br />

Prototype: long strtol(const char *s, char **endptr, int base);<br />

Arguments: s string to be converted<br />

endptr pointer to the character atwhich the conversion stopped<br />

base number base to use in conversion<br />

Return Value: Returns the converted number if successful; otherwise, returns 0.<br />

Remarks: If baseis zero, strtolattempts to determine the base automatically.<br />

It can be octal, determined by a leading zero, hexadecimal, determined<br />

by a leading 0x or 0X, or decimal in any other case. If base is specified<br />

strtolconverts a sequence of digits and letters a-z (case<br />

insensitive), where a-z represents the numbers 10-36. Conversion<br />

stops when an out of basenumber is encountered. endptrwill point to<br />

the remainder of the string starting with the first unconverted character.<br />

If a range error occurs, errnowill be set.<br />

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

#include /* for strtol */<br />

int main(void)<br />

{<br />

char *end;<br />

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

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

long x;<br />

x = strtol(a, &end, 16);<br />

printf("String = \"%s\" long = %ld\n", a, x );<br />

printf("Stopped at: %s\n\n", end );<br />

x = strtol(b, &end, 4);<br />

printf("String = \"%s\" long = %ld\n", b, x );<br />

printf("Stopped at: %s\n\n", end );<br />

}<br />

Output:<br />

String = "-12BGEE" long = -299<br />

Stopped at: GEE<br />

String = "1234Number" long = 27<br />

Stopped at: 4Number<br />

dsPIC<br />

4.15 CHỨC NĂNG STRING<br />

Các string.hconsists tập tin tiêu đề của các loại, macro và các chức năng cung<br />

cấp các công cụ<br />

để thao tác chuỗi.<br />

size_t<br />

Mô tả: Các loại kết quả của sizeofoperator.<br />

Bao gồm:<br />

NULL<br />

Mô tả: Giá trị của một con trỏ hằng null.<br />

Bao gồm:<br />

memchr<br />

Mô tả: Tọa lạc một nhân vật trong một bộ đệm.<br />

Bao gồm:<br />

Nguyên mẫu: void * memchr (const void * s, int c, size_t n);<br />

Đối số: s con trỏ vào bộ đệm<br />

c nhân vật để tìm kiếm<br />

số n của các nhân vật để kiểm tra<br />

Quay trở lại giá trị: Trả về một con trỏ đến vị trí của trận đấu nếu thành<br />

công; nếu không,<br />

trả về null.<br />

Bình luận: memchrstops khi nó tìm thấy sự xuất hiện đầu tiên của cor sau khi<br />

tìm kiếm<br />

nSố ký tự.<br />

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

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

int main (void)<br />

{<br />

char buf1 [50] = "Bây giờ là mấy?";<br />

char ch1 = 'i', CH2 = 'y';<br />

char * ptr;<br />

res int;<br />

printf ("buf1:% s \ n \ n", buf1);<br />

ptr = memchr (buf1, ch1, 50);<br />

if (ptr! = NULL)<br />

{<br />

res = ptr - buf1 1;<br />

printf ("% c tìm thấy ở vị trí% d \ n", ch1, độ phân giải);<br />

}<br />

khác<br />

printf ("% c không tìm thấy \ n", ch1);<br />

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

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

Saved successfully!

Ooh no, something went wrong!