C library functions - atoi ()
C standard library - <stdlib.h>
description
C library functionint atoi (const char * str) to convert a string argument strpoints to an integer (type int type).
statement
Here is () statement atoi function.
int atoi(const char *str)
parameter
- str - the string to be converted to an integer.
return value
This function returns the converted long integer if there is no implementation of an effective conversion, zero is returned.
Examples
The following example demonstrates the atoi () function is used.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int val; char str[20]; strcpy(str, "98993489"); val = atoi(str); printf("字符串值 = %s, 整型值 = %d\n", str, val); strcpy(str, "w3cschool.cc"); val = atoi(str); printf("字符串值 = %s, 整型值 = %d\n", str, val); return(0); }
Let's compile and run the above program, which will result in the following:
字符串值 = 98993489, 整型值 = 98993489 字符串值 = w3cschool.cc, 整型值 = 0