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.

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

int main(void)<br />

{<br />

char buf1[50] = "Where is the time?";<br />

char buf2[50] = "Where did they go?";<br />

char buf3[50] = "Why?";<br />

int res;<br />

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

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

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

res = strcmp(buf1, buf2);<br />

if (res < 0)<br />

printf("buf1 comes before buf2\n");<br />

else if (res == 0)<br />

printf("buf1 andbuf2 are equal\n");<br />

else<br />

printf("buf2 comes before buf1\n");<br />

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

res = strcmp(buf1, buf3);<br />

if (res < 0)<br />

printf("buf1 comes before buf3\n");<br />

else if (res == 0)<br />

printf("buf1 andbuf3 are equal\n");<br />

else<br />

printf("buf3 comes before buf1\n");<br />

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

res = strcmp("Why?", buf3);<br />

if (res < 0)<br />

printf("\"Why?\"comes before buf3\n");<br />

else if (res == 0)<br />

printf("\"Why?\" and buf3 are equal\n");<br />

else<br />

printf("buf3 comes before \"Why?\"\n");<br />

}<br />

Standard C Libraries with Math Functions<br />

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

Output:<br />

buf1 : Where is the time?<br />

buf2 : Where did they go?<br />

Trong kết quả thứ ba, không ai trong số các nhân vật của s1are trong s2so tất cả<br />

nhân vật được tính.<br />

dột<br />

Mô tả: Được một thông báo lỗi nội bộ.<br />

Bao gồm:<br />

Prototype: char * dột (int errcode);<br />

Errcode số của mã lỗi: Đối số<br />

Quay trở lại giá trị: Trả về một con trỏ đến một thông báo lỗi nội bộ để<br />

stringcorresponding<br />

mã lỗi errcode quy định.<br />

Ghi chú: Các mảng trỏ đến bởi strerrormay được ghi đè bởi một<br />

cuộc gọi tiếp theo để chức năng này.<br />

Ví dụ: # include / * Cho fopen, fclose, * /<br />

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

# include / * Cho dột * /<br />

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

int main (void)<br />

{<br />

FILE * myfile;<br />

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

printf ("Không thể mở samp.fil:% s \ n",<br />

dột (errno));<br />

khác<br />

printf ("Thành công mở samp.fil \ n");<br />

fclose (myfile);<br />

}<br />

Đầu ra:<br />

Không thể mở samp.fil: tập tin lỗi mở<br />

strlen<br />

Mô tả: Tìm chiều dài của một chuỗi.<br />

Bao gồm:<br />

Prototype: size_t strlen (const char * s);<br />

Đối số: s chuỗi<br />

Quay trở lại giá trị: Trả về độ dài của một chuỗi.<br />

Bình luận: Chức năng này quyết định độ dài của chuỗi, không bao gồm<br />

chấm dứt ký tự null.<br />

strcspn (Tiếp theo)<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ

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

Saved successfully!

Ooh no, something went wrong!