S
sudharsan
Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
could you please explain wat atoi( ) function is for and an example
how to use it?
sudharsan said:Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
how to use it?
sudharsan said:Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
sudharsan said:Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
Jaspreet said:Just pick up any book on C or do a man atoi to help you. It converts a
text to integer value.
for example atoi("234") would return you 234 as int on which you can
subsequently do arithmetic operations.
We also have itoa() and other similar functions.
char str[]= "234";
int iVal;
iVal = atoi(str);
It basically subtracts '0' from each character to get you the numeric.
Sunil said:Usage :
int atoi( const char *string );
Vladimir S. Oka said:Jaspreet wrote: [...]for example atoi("234") would return you 234 as int on which you can
subsequently do arithmetic operations.
We also have itoa() and other similar functions.
char str[]= "234";
int iVal;
iVal = atoi(str);
It basically subtracts '0' from each character to get you the numeric.
What a load of cobblers! Of course it does work that way, NOT!
Jaspreet said:We also have itoa() and other similar functions.
sudharsan said:Hi
could you please explain wat atoi( ) function is for and an example
how to use it?
Keith said:Vladimir S. Oka said:Jaspreet wrote: [...]for example atoi("234") would return you 234 as int on which you can
subsequently do arithmetic operations.
We also have itoa() and other similar functions.
char str[]= "234";
int iVal;
iVal = atoi(str);
It basically subtracts '0' from each character to get you the numeric.
What a load of cobblers! Of course it does work that way, NOT!
It could, and very likely does, subtract '0' from each character value
to get the numeric value of that digit. Of course that's not all it
does.
It could, and very likely does, subtract '0' from each character value
to get the numeric value of that digit. Of course that's not all it
does.
David said:Keith Thompson ha scritto:
Well, doing a `man atoi', it explains the function this way:
"
...
int atoi(const char *nptr);
...
The atoi() function converts the initial portion of the string pointed
to by nptr to int. The behaviour is the same as
strtol(nptr, (char **)NULL, 10);
except that atoi() does not detect errors."
Now, looking into stdlib.h, I see that strtol() refers to
__strtol_internal(), but I can't find it:
"
extern __inline long int __NTH (strtol (__const char *__restrict __nptr,
char **__restrict __endptr, int __base))
{
return __strtol_internal (__nptr, __endptr, __base, 0);
}
"
Does anyone have a slight idea where __strtol_internal is placed?
(I just want to understand how atoi() effectively works)
...
It is placed in the standard library implementation. You may not have
access to the source code for it (you might if you're using gcc). Even
if you had, it's not guaranteed to be in C, or any other language you
can think of.
The best way to really understand that is to try and code it yourself.
If the string cannot be converted to a number, at all, atoi
returns zero.
The return value is 0 if the input cannot be converted to a value of
that type.
Richard said:Sunil Varma said:
Chapter and verse please.
Richard said:Ron Lima said:
Chapter and verse, please.
pete said:Richard said:Ron Lima said:
Chapter and verse, please.
It depends on whether "no conversion" is the same thing as "error".
Is atoi(""), an error?
N869
7.20.1.2 The atoi, atol, and atoll functions
[#2] The atoi, atol, and atoll functions convert the initial
portion of the string pointed to by nptr to int, long int,
and long long int representation, respectively. Except for
the behavior on error, they are equivalent to
atoi: (int)strtol(nptr, (char **)NULL, 10)
7.20.1.4 The strtol, strtoll, strtoul, and strtoull
functions
[#7] If the subject sequence is empty or does not have the
expected form, no conversion is performed; the value of nptr
is stored in the object pointed to by endptr, provided that
endptr is not a null pointer.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.