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: Converts a string to an integer.<br />

Include: <br />

Prototype: int atoi(const char *s);<br />

Argument: s string to be converted<br />

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

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

[whitespace] [sign] digits<br />

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

of one or more digits. The conversion stops when the first<br />

unrecognized character is reached. The conversion is equivalent to<br />

(int) strtol(s,0,10)except it does no error checking so errno<br />

will not be set.<br />

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

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

int main(void)<br />

{<br />

char a[] = " -127";<br />

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

int x;<br />

x = atoi(a);<br />

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

x = atoi(b);<br />

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

}<br />

Output:<br />

String = " -127" int = -127<br />

String = "Number1" int = 0<br />

atol<br />

Description: Converts a string to a long integer.<br />

Include: <br />

Prototype: long atol(const char *s);<br />

Argument: s string to be converted<br />

Return Value: Returns the converted longinteger if successful; otherwise,<br />

returns 0<br />

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

[whitespace] [sign] digits<br />

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

of one or more digits. The conversion stops when the first<br />

unrecognized character is reached. The conversion is equivalent to<br />

Bao gồm:<br />

Nguyên mẫu: void * calloc (size_t nelem, size_t size);<br />

Đối số: số nelem của các yếu tố<br />

chiều dài kích thước của mỗi phần tử<br />

Quay trở lại giá trị: Trả về một con trỏ đến không gian được phân bổ nếu thành<br />

công; nếu không,<br />

trả về một con trỏ null.<br />

Ghi chú: Bộ nhớ được trả về bởi callocis liên kết chính xác cho bất kỳ dữ liệu<br />

kích thước<br />

phần tử và được khởi tạo bằng không.<br />

Ví dụ: / * Chương trình này cấp phát bộ nhớ cho * /<br />

/ * Mảng 'i' của longintegers và khởi tạo * /<br />

/ * Chúng bằng không. * /<br />

# include / * Cho printf, NULL * /<br />

# include / * Cho calloc, * miễn phí /<br />

int main (void)<br />

{<br />

int x;<br />

dài * i;<br />

i = (long *) calloc (5, sizeof (long));<br />

if (i! = NULL)<br />

{<br />

for (x = 0; x

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

Saved successfully!

Ooh no, something went wrong!