- 1
What is the use of atoi function in c
I don't understand the concept please give me an explanation with example
11 Answers
+ 7
char
number
atoi
+ 5
~ swim ~ it returns 0 i think if the string is not digit
+ 4
Converts an string to integer.
+ 3
Gayathri Manalan - or + are valid chars for atoi. atoi("-56") retuns -56
ā³AsterisKā³ undefined behaviour if the number is out of range. But if not a number it returns zero as ~ swim ~ said...
atoi("555555555555555") --> undefinded
atoi(" -56") --> -56
atoi("fghi") --> 0
:)
+ 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int val; char str[20];
strcpy(str, "98993489");
val = atoi(str);
printf("String value = %s, Int value = %d\n", str, val);
strcpy(str, "hello");
val = atoi(str);
printf("String value = %s, Int value = %d\n", str, val);
return(0);
}
Run this code using numbers and alphabetic. You will understand better.
+ 1
In simple words "654" value is not equal to 654.
So it converts "654" to 654 value...šššš
+ 1
It stands for ASCII to Integer.
+ 1
the atoi() converts a string to an integer and atoi() skips all white-space characters at the beginning of the string.
0
char
number
atoi