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.

str1, str2, res);<br />

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

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

str3, str2, res);<br />

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

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

str3, str4, res);<br />

}<br />

Output:<br />

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

strcspn("animal", "aeiou") = 0<br />

strcspn("animal", "xyz") = 6<br />

strcpy (Continued)<br />

Standard C Libraries with Math Functions<br />

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

Explanation:<br />

In the first result, eis in s2so it stops counting after h.<br />

In the second result, ais in s2.<br />

In the third result, none of the characters of s1are in s2so all<br />

characters are counted.<br />

strerror<br />

Description: Gets an internal error message.<br />

Include: <br />

Prototype: char *strerror(int errcode);<br />

Argument: errcode number of the error code<br />

Return Value: Returns a pointer to an internal error message<br />

stringcorresponding to<br />

the specified error code errcode.<br />

Remarks: The array pointed to by strerrormay be overwritten by a<br />

subsequent call to this function.<br />

Example: #include /* for fopen, fclose, */<br />

/* printf, FILE, NULL */<br />

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

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

int main(void)<br />

{<br />

FILE *myfile;<br />

if ((myfile = fopen("samp.fil", "r+")) == NULL)<br />

printf("Cannot open samp.fil: %s\n",<br />

Chúng tôi hereWhere<br />

(16 ký tự)<br />

buf1 sau strncat 25 ký tự của buf2:<br />

Chúng tôi hereWhere ở đâu thời gian?<br />

(34 ký tự)<br />

buf1 sau strncat của 4 nhân vật của buf3:<br />

Chúng tôi hereWhere ở đâu thời gian? Tại sao?<br />

(38 ký tự)<br />

strncat (Tiếp theo)<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 308<br />

strncmp<br />

2004 Microchip Technology Inc<br />

Mô tả: So sánh hai chuỗi, cho đến một số quy định của ký tự.<br />

Bao gồm:<br />

Nguyên mẫu: int strncmp (const char * s1, const char * s2,<br />

size_t n);<br />

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

s2 chuỗi 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 />

Bình luận: strncmpreturns một giá trị dựa trên các nhân vật đầu tiên mà khác<br />

giữa s1and s2. Nhân vật tiếp theo một ký tự null không<br />

so sánh.<br />

Ví dụ: # include / * Cho strncmp * /<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 = strncmp (buf1, buf2, 6);<br />

if (res

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

Saved successfully!

Ooh no, something went wrong!