Atoi() - C library function Program
Declaration :
int atoi(const char *str)
Explanation :
Purpose | The C library function int atoi(const char *str) converts the string argument str to an integer (type int). |
Parameters | str ===> This is the string representation of an integral number. |
Return Value | This function returns the converted integral number as an int value. If no valid conversion could be performed it returns zero. |
Exception |
C Program : Example
The following example shows the usage of atoi() function.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int value; char str[20]; strcpy(str, "1234"); value= atoi(str); printf("\nString equivalent value of %s = %d", str, value); strcpy(str, "pritesh"); value= atoi(str); printf("\nString equivalent value of %s = %d", str, value); return(0); }
Output :
String equivalent value of 1234 = 1234 String equivalent value of pritesh = 0