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