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.

strerror(errno));<br />

else<br />

printf("Success opening samp.fil\n");<br />

fclose(myfile);<br />

}<br />

Output:<br />

Cannot open samp.fil: file open error<br />

strlen<br />

Description: Finds the length of a string.<br />

Include: <br />

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

Argument: s the string<br />

Return Value: Returns the length of a string.<br />

Remarks: This function determines the length of the string, not including the<br />

terminating null character.<br />

strcspn (Continued)<br />

dsPIC<br />

®<br />

Language Tools Libraries<br />

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

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

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

int main(void)<br />

{<br />

char str1[20] = "We are here";<br />

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

char str3[20] = "Why me?";<br />

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

printf("\t(string length = %d characters)\n\n",<br />

strlen(str1));<br />

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

printf("\t(string length = %d characters)\n\n",<br />

strlen(str2));<br />

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

printf("\t(string length = %d characters)\n\n\n",<br />

strlen(str3));<br />

}<br />

Output:<br />

str1 : We are here<br />

printf ("buf1 đến trước buf2 \ n");<br />

if (res == 0)<br />

printf ("6 charactersof buf1 và buf2"<br />

"Bằng nhau \ n");<br />

khác<br />

printf ("buf2 đến trước buf1 \ n");<br />

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

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

if (res

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

Saved successfully!

Ooh no, something went wrong!