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.

®<br />

Language Tools Libraries<br />

DS51456B-page 314<br />

Output:<br />

strspn("animal", "aeiounm") = 5<br />

strspn("animal", "aimnl") = 6<br />

strspn("animal", "xyz") = 0<br />

Explanation:<br />

In the first result, lis not in s2.<br />

2004 Microchip Technology Inc.<br />

In the second result, the terminating null is not in s2.<br />

In the third result, ais not in s2, so the comparison stops.<br />

strstr<br />

Description: Search for the first occurrence ofa string inside another string.<br />

Include: <br />

Prototype: char *strstr(const char *s1, const char *s2);<br />

Arguments: s1 pointer to the string to be searched<br />

s2 pointer to substring to be searched for<br />

Return Value: Returns the address of the first element that matches the substring<br />

if<br />

found; otherwise, returns a null pointer.<br />

Remarks: This function will find the first occurrence of the string s2(excluding<br />

the<br />

null terminator) within the string s1. If s2points to a zero length string,<br />

s1is returned.<br />

Example: #include /* for strstr, NULL */<br />

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

int main(void)<br />

{<br />

char str1[20] = "What time is it?";<br />

char str2[20] = "is";<br />

char str3[20] = "xyz";<br />

char *ptr;<br />

int res;<br />

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

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

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

ptr = strstr(str1, str2);<br />

if (ptr != NULL)<br />

{<br />

res = ptr - str1 + 1;<br />

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

2004 Microchip Technology Inc DS51456B trang 317<br />

4.16 Ngày giờ CHỨC NĂNG<br />

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

thời gian.<br />

clock_t<br />

Mô tả: Cửa hàng xử lý thời gian giá trị.<br />

Bao gồm:<br />

Prototype: typedef clock_t dài<br />

size_t<br />

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

Bao gồm:<br />

struct tm<br />

Mô tả: Cơ cấu sử dụng để giữ thời gian và ngày (thời gian lịch).<br />

Bao gồm:<br />

Nguyên mẫu: struct tm {<br />

int tm_sec; / * Giây sau khi phút (0-61) * /<br />

/ * Cho phép đến hai giây nhuận * /<br />

int tm_min; / * Phút sau khi giờ (0-59) * /<br />

int tm_hour; / * Giờ kể từ nửa đêm (0-23) * /<br />

int tm_mday; / * Ngày trong tháng (1-31) * /<br />

int tm_mon; / * Tháng (0-11 tháng một nơi = 0) * /<br />

int tm_year; / * Năm kể từ năm 1900 * /<br />

int tm_wday; / * Ngày trong tuần (0-6 nơi chủ nhật = 0) * /<br />

int tm_yday; / * Ngày trong năm (0-365 nơi 01 tháng 1 = 0) * /<br />

int tm_isdst; / * Daylight Savings Time cờ * /<br />

}<br />

Ghi chú: Nếu tm_isdst isa giá trị tích cực, ánh sáng ban ngày tiết kiệm có hiệu<br />

lực. Nếu đó là<br />

thời gian không, tiết kiệm ánh sáng không có hiệu lực. Nếu đó là một giá trị âm<br />

tình trạng của Daylight Saving Time không được biết đến.<br />

time_t<br />

Mô tả: Đại diện cho các giá trị thời gian lịch.<br />

Bao gồm:<br />

Prototype: typedef time_t dài<br />

CLOCKS_PER_SEC<br />

Mô tả: Số đồng hồ xử lý mỗi giây.<br />

Bao gồm:<br />

Prototype: # define CLOCKS_PER_SEC<br />

Giá trị: 1<br />

Bình luận: MPLAB C30 trả về bọ ve đồng hồ (chu kỳ hướng dẫn) không phải

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

Saved successfully!

Ooh no, something went wrong!