Linux C's atio () function

Source: Internet
Author: User

Linux C's atio () function

1. Start with man

Atoi (3) Linux programmer's Manual atoi (3)

Name

Atoi, atol, atoll, atoq-convert a string to an integer

Synopsis

# Include <stdlib. h>

 

Int atoi (const char * nptr );

Long atol (const char * nptr );

Long long Atoll (const char * nptr );

Long long atoq (const char * nptr );

 

Feature test macro requirements for glibc (seefeature_test_macros (7 )):

Atoll (): _ bsd_source | _ svid_source | _ xopen_source> = 600 |

_ Isoc99_source; or Cc-STD = c99

Description

The atoi () function converts the initial portion ofthe string pointed to by nptr to int. the behavior is the same as strtol (nptr, (char **) null, 10); doesn't thatatoi () does not detect errors. the atol () and Atoll () functions behave the sameas atoi (), doesn't that they convert Theinitial portion of the string to their return type of longor long. atoq () is an obsolete namefor Atoll ().

Return Value

The converted value.

Ii. Use of atoi () Functions

1. Function functions:

Converts a string to an integer.

2. prototype:

Int atoi (const char * nptr );

3. function Description: nptr string. If the first non-space character does not exist or is neither a number nor a plus or minus sign, zero is returned. Otherwise, type conversion is started, the conversion is stopped when a non-Numeric (including the terminator \ 0) character is detected. The integer number is returned.

4. header file: # include <stdlib. h>

5. program example:

1>

# Include <stdlib. h>

# Include <stdio. h>

Int main (void)

{

Int N;

Char * STR = "12345.67 ";

N = atoi (STR );

Printf ("string = % s integer = % d \ n", STR, N );

Return 0;

}

Execution result

String = 12345.67 integer = 12345

2>

# Include <stdlib. h>

# Include <stdio. h>

Int main ()

{

Char A [] = "-100 ";

Char B [] = "123 ";

Int C;

C = atoi (A) + atoi (B );

Printf ("c = % d \ n", C );

Return 0;

}

Execution result

C = 23

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.