Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What's the use of the function atoi ()? What is his header file? Can it be used in Vi editor under Linux?
What's the use of the function atoi ()? What is his header file? Can it be used in Vi editor under Linux?
1, atoi (for ascii to integer) is a function that converts character strings into integers, which is used in computer programs and office software.

2. Header file: # include

3. It can be used in Vi editor under Linux.

Int atoi(const char *nptr) function scans the parameter nptr string and skips leading white space characters (such as spaces and tab indentation). If nptr cannot be converted to int or nptr is an empty string, return 0? . In particular, this function requires that the converted string be understood as a decimal number.

Extended data

Example:

1 & gt;

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

int main(void)

{

int n;

char * str = " 12345.67 ";

n = atoi(str);

printf("string = %s integer =%d\n ",str,n);

Returns 0;

}

Execution result

String = 12345.67 Integer =12345,000

2 & gt

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

int main()

{

char a[]= "- 100 ";

char b[]= " 123 ";

int c;

c = atoi(a)+atoi(b);

printf("c = %d\n ",c);

Returns 0;

}

Execution result

c = 23

Baidu Encyclopedia -—atoi ()