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.

Standard C Libraries with Math Functions<br />

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

srand<br />

Description: Set the starting seed for the pseudo-random number sequence.<br />

Include: <br />

Prototype: void srand(unsigned int seed);<br />

Argument: seed starting value for the pseudo-random number sequence<br />

Return Value: None<br />

Remarks: This function sets the starting seed for the pseudo-random number<br />

sequence generated by the randfunction. The randfunction will<br />

always return the same sequence of integers when identical seed<br />

values are used. If randis called with a seed value of 1, the sequence<br />

of numbers generated will be the same as if randhad been called<br />

without srandhaving been called first.<br />

Example: #include /* forprintf */<br />

#include /* for rand, srand */<br />

int main(void)<br />

{<br />

int x;<br />

srand(7);<br />

for (x = 0; x < 5; x++)<br />

printf("Number = %d\n", rand());<br />

}<br />

Output:<br />

Number = 16327<br />

Number = 5931<br />

Number = 23117<br />

Number = 30985<br />

Number = 29612<br />

strtod<br />

Description: Converts a partial string to a floating-point number of type double.<br />

Include: <br />

Prototype: double strtod(const char *s, char **endptr);<br />

Arguments: s string to be converted endptr pointer to the character at which the<br />

conversion stopped<br />

Return Value: Returns the converted number 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 />

xác định<br />

bởi một hàng đầu 0x hoặc 0X, hoặc thập phân trong các trường hợp khác. Nếu<br />

cơ sở được quy định<br />

strtolconverts một chuỗi số và chữ cái az (trường hợp<br />

không nhạy cảm), nơi az đại diện cho số 10-36. Chuyển đổi<br />

dừng lại khi một trong số cơ số là gặp phải. điểm để endptrwill<br />

phần còn lại của chuỗi bắt đầu với nhân vật không thể đảo ngược đầu tiên.<br />

Nếu một lỗi xảy ra nhiều, errnowill được thiết lập.<br />

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

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

int main (void)<br />

{<br />

char * kết thúc;<br />

char a [] = "12BGET3";<br />

char b [] = "0x1234Number";<br />

char c [] = "-123abc";<br />

x unsigned dài;<br />

x = strtoul (a, và kết thúc, 25);<br />

printf ("String = \"% s \ "dài =% lu \ n", a, x);<br />

printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />

x = strtoul (b, và kết thúc, 0);<br />

printf ("String = \"% s \ "dài =% lu \ n", b, x);<br />

printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />

x = strtoul (c, và kết thúc, 0);<br />

printf ("String = \"% s \ "dài =% lu \ n", c, x);<br />

printf ("Ngưng tại:% s \ n \ n", kết thúc);<br />

}<br />

Đầu ra:<br />

String = "12BGET3" dài = 429.164<br />

Dừng lại ở: T3<br />

String = "0x1234Number" dài = 4660<br />

Dừng lại ở: Số<br />

String = "-123abc" dài = 4294967173<br />

Dừng lại ở: abc<br />

Thư viện chuẩn C với hàm toán học<br />

2004 Microchip Technology Inc DS51456B trang 293<br />

hệ thống<br />

Mô tả: Thực hiện một lệnh.<br />

Bao gồm:<br />

Nguyên mẫu: int hệ thống (const char * s);

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

Saved successfully!

Ooh no, something went wrong!