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.

Description: Generates a pseudo-random integer.<br />

Include: <br />

Prototype: int rand(void);<br />

Return Value: Returns an integer between 0 and RAND_MAX.<br />

Remarks: Calls to this function return pseudo-random integer values in the<br />

range<br />

[0,RAND_MAX]. To use this function effectively, you must seed the<br />

random number generator using the srandfunction. This function will<br />

always return the same sequence ofintegers when no seeds are used<br />

(as in the example below) or whenidentical seed values are used. (See<br />

srandfor seed example.)<br />

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

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

int main(void)<br />

{<br />

int x;<br />

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

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

}<br />

Output:<br />

Number = 21422<br />

Number = 2061<br />

Number = 16443<br />

Number = 11617<br />

Number = 9125<br />

Notice if the program is run a second time, the numbers are the same.<br />

See the example for srandto seed the random number generator.<br />

realloc<br />

Description: Reallocates memory to allow a size change.<br />

Include: <br />

Prototype: void *realloc(void *ptr, size_t size);<br />

Arguments: ptr points to previously allocated memory<br />

size new size to allocate to<br />

Return Value: Returns a pointer to the allocated space if successful; otherwise,<br />

returns a null pointer.<br />

Remarks: If the existing object is smaller than the new object, the entire existing<br />

object is copied to the new object and the remainder of the new object<br />

is indeterminate. If the existing object is larger than the new object, the<br />

function copies as much of the existing object as will fit in the new<br />

int main (void)<br />

{<br />

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

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

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

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

x đôi;<br />

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

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

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

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

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

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

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

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

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

}<br />

Đầu ra:<br />

String = "1.28 inch" float = 1,280000<br />

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

String = "27.835e2i" float = 2783,500000<br />

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

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

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

strtod (Tiếp theo)<br />

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

2004 Microchip Technology Inc DS51456B trang 291<br />

strtol<br />

Mô tả: Chuyển đổi một chuỗi một phần một số nguyên dài.<br />

Bao gồm:<br />

Prototype: strtol dài (const char * s, char ** endptr, int cơ sở);<br />

Đối số: chuỗi s được chuyển đổi<br />

endptr con trỏ đến các nhân vật atwhich chuyển đổi dừng lại<br />

cơ sở số lượng cơ sở để sử dụng trong chuyển đổi<br />

Quay trở lại giá trị: Trả về số chuyển đổi nếu thành công; nếu không, trả về 0.<br />

Ghi chú: Nếu baseis số không, strtolattempts để xác định các cơ sở tự động.<br />

Nó có thể là bát phân, xác định bởi một số không hàng đầu, hệ thập lục phân,<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

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

Saved successfully!

Ooh no, something went wrong!