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.

contained in s2.<br />

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

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

int main(void)<br />

{<br />

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

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

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

char *ptr;<br />

int res;<br />

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

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

if (ptr != NULL)<br />

{<br />

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

printf("match foundat position %d\n", res);<br />

}<br />

else<br />

printf("match not found\n");<br />

strncpy (Continued)<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

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

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

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

ptr = strpbrk(str1, str3);<br />

if (ptr != NULL)<br />

{<br />

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

printf("match found at position %d\n", res);<br />

}<br />

else<br />

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

}<br />

Output:<br />

strpbrk("What time isit?", "xyz")<br />

match not found<br />

strpbrk("What time isit?", "eou?")<br />

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

int main (void)<br />

{<br />

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

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

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

char * ptr;<br />

res int;<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 />

printf ("\"% s \ "được tìm thấy ở vị trí% d \ n",<br />

str2, độ phân giải);<br />

}<br />

khác<br />

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

strspn (Tiếp theo)<br />

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

2004 Microchip Technology Inc DS51456B trang 315<br />

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

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

if (ptr! = NULL)<br />

{<br />

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

printf ("\"% s \ "được tìm thấy ở vị trí% d \ n",<br />

str3, độ phân giải);<br />

}<br />

khác<br />

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

}<br />

Đầu ra:<br />

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

str2: là<br />

str3: xyz<br />

"Được" tìm thấy ở vị trí 11

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

Saved successfully!

Ooh no, something went wrong!