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.

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

memcpy(buf1, buf3, 5);<br />

printf("buf1 after memcpy of 5 chars of "<br />

"buf3: \n\t%s\n", buf1);<br />

}<br />

Output:<br />

buf1 :<br />

buf2 : Where is the time?<br />

buf3 : Why?<br />

buf1 after memcpy of6 chars of buf2:<br />

Where<br />

buf1 after memcpy of5 chars of buf3:<br />

Why?<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

DS51456B-page 298<br />

memmove<br />

2004 Microchip Technology Inc.<br />

Description: Copies n characters of the sourcebuffer into the destination buffer,<br />

even if the regions overlap.<br />

Include: <br />

Prototype: void *memmove(void *s1, const void *s2, size_t n);<br />

Arguments: s1 buffer to copy characters to (destination)<br />

s2 buffer to copy characters from (source)<br />

n number of characters to copy from s2to s1<br />

Return Value: Returns a pointer to the destination buffer<br />

Remarks: If the buffers overlap, the effect is asif the characters are read first<br />

from<br />

s2then written to s1so the buffer is not corrupted.<br />

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

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

int main(void)<br />

{<br />

char buf1[50] = "When time marches on";<br />

char buf2[50] = "Where is the time?";<br />

char buf3[50] = "Why?";<br />

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

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

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

Chúng tôi hereWhere là thời gian? Tại sao?<br />

(32 ký tự)<br />

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

2004 Microchip Technology Inc DS51456B trang 301<br />

strchr<br />

Mô tả: Tọa lạc xuất hiện đầu tiên của một nhân vật được quy định trong một<br />

chuỗi.<br />

Bao gồm:<br />

Prototype: char * strchr (const char * s, int c);<br />

Đối số: s con trỏ đến chuỗi<br />

c nhân vật để tìm kiếm<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ề một con trỏ null.<br />

Bình luận: chức năng này tìm kiếm chuỗi sto tìm sự xuất hiện đầu tiên của<br />

nhân vật c.<br />

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

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

int main (void)<br />

{<br />

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

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

char * ptr;<br />

res int;<br />

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

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

if (ptr! = NULL)<br />

{<br />

res = ptr - buf1 1;<br />

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

}<br />

khác<br />

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

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

ptr = strchr (buf1, CH2);<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 />

}

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

Saved successfully!

Ooh no, something went wrong!