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("buf1 : %s\n\n", buf1);<br />

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

if (ptr != NULL)<br />

{<br />

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

printf("%c found atposition %d\n", ch1, res);<br />

}<br />

else<br />

printf("%c not found\n", ch1);<br />

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

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

if (ptr != NULL)<br />

{<br />

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

printf("%c found atposition %d\n", ch2, res);<br />

}<br />

else<br />

printf("%c not found\n", ch2);<br />

}<br />

Output:<br />

buf1 : What time is it?<br />

m found at position 8<br />

y not found<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

DS51456B-page 302<br />

strcmp<br />

Description: Compares two strings.<br />

Include: <br />

2004 Microchip Technology Inc.<br />

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

Arguments: s1 first string<br />

s2second string<br />

Return Value: Returns a positive number if s1is greater than s2, zero if s1is<br />

equal to<br />

s2, or a negative number if s1is less than s2.<br />

Remarks: This function compares successive characters from s1and s2until<br />

they are not equal or the null terminator is reached.<br />

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

Mô tả: Tính toán số lượng các ký tự liên tiếp vào đầu của một<br />

chuỗi không được containedin một tập hợp các ký tự.<br />

Bao gồm:<br />

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

Đối số: con trỏ s1 vào chuỗi cần tìm kiếm<br />

s2 con trỏ đến ký tự để tìm kiếm<br />

Quay trở lại giá trị: Trả về độ dài của phân khúc này trong s1not chứa các ký tự<br />

được tìm thấy trong s2.<br />

Bình luận: chức năng này sẽ xác định các ký tự liên tiếp từ numberof<br />

đầu s1that không có trong s2.<br />

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

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

int main (void)<br />

{<br />

char str1 [20] = "hello";<br />

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

char str3 [20] = "động vật";<br />

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

res int;<br />

res = strcspn (str1, str2);<br />

printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />

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

res = strcspn (str3, str2);<br />

printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />

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

res = strcspn (str3, str4);<br />

printf ("strcspn (\"% s \ ", \"% s \ ") =% d \ n",<br />

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

}<br />

Đầu ra:<br />

strcspn ("hello", "aeiou") = 1<br />

strcspn ("động vật", "aeiou") = 0<br />

strcspn ("động vật", "xyz") = 6<br />

strcpy (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 305<br />

Giải thích:<br />

Trong kết quả đầu tiên, eis trong s2so nó ngừng đếm sau khi h.<br />

Trong kết quả thứ hai, ais trong s2.

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

Saved successfully!

Ooh no, something went wrong!