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.

printf("\t(%d characters)\n", strlen(buf1));<br />

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

strcat(buf1, "Why?");<br />

printf("buf1 after strcatof \"Why?\": \n\t%s\n",<br />

buf1);<br />

printf("\t(%d characters)\n", strlen(buf1));<br />

}<br />

Output:<br />

buf1 : We're here<br />

(10 characters)<br />

buf2 : Where is the time?<br />

(18 characters)<br />

buf1 after strcat of buf2:<br />

We're hereWhere is the time?<br />

(28 characters)<br />

buf1 after strcat of "Why?":<br />

We're hereWhere is the time?Why?<br />

(32 characters)<br />

Standard C Libraries with Math Functions<br />

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

strchr<br />

Description: Locates the first occurrence of a specified character in a string.<br />

Include: <br />

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

Arguments: s pointer to the string<br />

c character to search for<br />

Return Value: Returns a pointer to the location of the match if successful;<br />

otherwise,<br />

returns a null pointer.<br />

Remarks: This function searches the string sto find the first occurrence of the<br />

character c.<br />

Example: #include /* forstrchr, NULL */<br />

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

int main(void)<br />

{<br />

char buf1[50] = "What time is it?";<br />

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

char *ptr;<br />

int res;<br />

Mô tả: Sao chép chuỗi nguồn vào chuỗi đích.<br />

Bao gồm:<br />

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

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

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

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

Bình luận: Tất cả các nhân vật của s2are sao chép, bao gồm ký tự chấm dứt nul<br />

Nếu chuỗi chồng chéo lên nhau, hành vi này là không xác định.<br />

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

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

int main (void)<br />

{<br />

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

char buf2 [50] = "đâu là thời điểm";<br />

char buf3 [50] = "Tại sao?";<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 sau strcpy của buf2: \ n \ t% s \ n \ n",<br />

buf1);<br />

strcmp (Tiếp theo)<br />

dsPIC<br />

®<br />

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

DS51456B trang 304 2004 Microchip Technology Inc<br />

strcpy (buf1, buf3);<br />

printf ("buf1 sau strcpy của buf3: \ n \ t% s \ n",<br />

buf1);<br />

}<br />

Đầu ra:<br />

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

buf2: đâu là thời gian?<br />

buf3: Tại sao?<br />

buf1 sau strcpy của buf2:<br />

Ở đâu thời gian?<br />

buf1 sau strcpy của buf3:<br />

Tại sao?<br />

strcspn

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

Saved successfully!

Ooh no, something went wrong!