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.

Language Tools Libraries<br />

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

atof<br />

Description: Converts a string to a double precision floating-point value.<br />

Include: <br />

Prototype: double atof(const char *s);<br />

Argument: s pointer to the string to be converted<br />

Return Value: Returns the converted value if successful; otherwise, returns 0.<br />

Remarks: The number may consist of the following:<br />

[whitespace] [sign] digits [.digits]<br />

[ { e | E }[sign]digits]<br />

optional whitespace, followed by an optional signthen a sequence<br />

of one or more digitswith an optional decimal point, followed by one<br />

or more optional digitsand an optional eor Efollowed by an optional<br />

signed exponent. The conversion stops when the first unrecognized<br />

character is reached. The conversion is the same as strtod(s,0,0)<br />

except it does no error checking so errnowill not be set.<br />

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

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

int main(void)<br />

{<br />

char a[] = " 1.28";<br />

char b[] = "27.835e2";<br />

char c[] = "Number1";<br />

double x;<br />

x = atof(a);<br />

printf("String = \"%s\" float = %f\n", a, x);<br />

x = atof(b);<br />

printf("String = \"%s\" float = %f\n", b, x);<br />

x = atof(c);<br />

printf("String = \"%s\" float = %f\n", c, x);<br />

}<br />

Output:<br />

String = "1.28" float = 1.280000<br />

String = "27.835:e2"float = 2783.500000<br />

String = "Number1" float = 0.000000<br />

Standard C Libraries with Math Functions<br />

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

atoi<br />

qsort (danh sách, NUM, sizeof (int), comp);<br />

printf ("Sắp xếp liệt kê:");<br />

for (x = 0; x

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

Saved successfully!

Ooh no, something went wrong!