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.

®<br />

Language Tools Libraries<br />

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

strtoul<br />

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

Include: <br />

Prototype: unsigned long strtoul(const char *s, char **endptr,<br />

int base);<br />

Arguments: s string to be converted<br />

endptr pointer to the character at which 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 base number 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 strtoul */<br />

int main(void)<br />

{<br />

char *end;<br />

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

char b[] = "0x1234Number";<br />

char c[] = "-123abc";<br />

unsigned long x;<br />

x = strtoul(a, &end, 25);<br />

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

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

x = strtoul(b, &end, 0);<br />

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

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

x = strtoul(c, &end, 0);<br />

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

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

}<br />

2004 Microchip Technology Inc DS51456B trang 295<br />

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

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

if (ptr! = NULL)<br />

{<br />

res = ptr - buf1 1;<br />

printf ("% c tìm thấy atposition% d \ n", CH2, độ phân giải);<br />

}<br />

khác<br />

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

}<br />

Đầu ra:<br />

buf1: Bây giờ là mấy?<br />

tôi tìm thấy ở vị trí 7<br />

y không tìm thấy<br />

memcmp<br />

Mô tả: So sánh nội dung của hai bộ đệm.<br />

Bao gồm:<br />

Nguyên mẫu: int memcmp (const void * s1, const void * s2, size_t n);<br />

Đối số: s1 đệm đầu tiên<br />

s2 đệm thứ hai<br />

số n ký tự để so sánh<br />

Quay trở lại giá trị: Trả về một số dương nếu s1is lớn hơn s2, bằng không nếu<br />

s1is bằng<br />

s2, hoặc một số âm nếu s1is ít hơn s2.<br />

Ghi chú: Chức năng này so sánh ncharacters đầu tiên trong s1to n đầu tiên<br />

nhân vật trong s2and trả về một giá trị cho biết liệu bộ đệm<br />

ít hơn, bằng hoặc lớn hơn so với nhau.<br />

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

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

int main (void)<br />

{<br />

char buf1 [50] = "đâu là thời điểm";<br />

char buf2 [50] = "Họ đã đi đâu?";<br />

char buf3 [50] = "Tại sao?";<br />

res int;<br />

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

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

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

res = memcmp (buf1, buf2, 6);

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

Saved successfully!

Ooh no, something went wrong!