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.

uf3 : Why?<br />

buf2 comes before buf1<br />

buf1 comes before buf3<br />

"Why?" and buf3 are equal<br />

strcoll<br />

Description: Compares one string to another. (See Remarks.)<br />

Include: <br />

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

Arguments: s1 first string<br />

s2 second string<br />

Return Value: Using the locale-dependent rules, itreturns a positive number if<br />

s1is<br />

greater than s2, zero if s1is equal to s2, or a negative number if s1is<br />

less than s2.<br />

Remarks: Since MPLAB C30 does not support alternate locales, this function is<br />

equivalent to strcmp.<br />

strcpy<br />

Description: Copy the source string into the destination string.<br />

Include: <br />

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

Arguments: s1 destination string to copy to<br />

s2 source string to copy from<br />

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

Remarks: All characters of s2are copied, including the null terminating<br />

character.<br />

If the strings overlap, the behavior is undefined.<br />

Example: #include /* forstrcpy, strlen */<br />

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

int main(void)<br />

{<br />

char buf1[50] = "We're here";<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 />

strcpy(buf1, buf2);<br />

printf("buf1 after strcpy of buf2: \n\t%s\n\n",<br />

buf1);<br />

strcmp (Continued)<br />

DS51456B trang 306<br />

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

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

int main (void)<br />

{<br />

2004 Microchip Technology Inc<br />

char str1 [20] = "Chúng tôi đang ở đây";<br />

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

char str3 [20] = "Sao lại là tôi?";<br />

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

printf ("\ t (string chiều dài =% d ký tự) \ n \ n",<br />

strlen (str1));<br />

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

printf ("\ t (string chiều dài =% d ký tự) \ n \ n",<br />

strlen (str2));<br />

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

printf ("\ t (string chiều dài =% d ký tự) \ n \ n \ n",<br />

strlen (str3));<br />

}<br />

Đầu ra:<br />

str1: Chúng tôi đang ở đây<br />

(Chiều dài chuỗi = 11 ký tự)<br />

str2:<br />

(Chiều dài chuỗi = 0 ký tự)<br />

str3: Tại sao tôi không?<br />

(Chiều dài chuỗi = 7 ký tự)<br />

strncat<br />

Mô tả: Thêm một số quy định của ký tự từ chuỗi nguồn đến<br />

chuỗi đích.<br />

Bao gồm:<br />

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

Đối số: s1 chuỗi đích để sao chép vào<br />

chuỗi nguồn s2 sao chép từ<br />

số n của các nhân vật để phụ thêm<br />

Quay trở lại giá trị: Trả về một con trỏ đến chuỗi đích.<br />

Ghi chú: Chức năng này gắn thêm lên đến ncharacters (một nhân vật vô giá trị<br />

và<br />

nhân vật mà theo nó không nối) từ chuỗi nguồn đến<br />

kết thúc của chuỗi đích. Nếu một ký tự null không gặp, sau đó<br />

một ký tự null chấm dứt được gắn vào kết quả. Nếu dây<br />

chồng chéo lên nhau, hành vi này là không xác định.

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

Saved successfully!

Ooh no, something went wrong!