Re: what is atoi( )
David Paleino wrote:[color=blue]
>
> Mark McIntyre ha scritto:[color=green]
> > On Fri, 03 Mar 2006 12:22:32 +0100, in comp.lang.c , David Paleino
> > <d.paleino@gmai l.com> wrote:
> >
> >[color=darkred]
> >>Yes, I'm using gcc, the problem is that I can't really find it:[/color]
> >
> >
> > You really don't need to.
> >
> >[color=darkred]
> >>As you can see, at least in /usr/include, there isn't a single
> >>definition for __strtol_intern al.[/color]
> >
> >
> > *shrug*. It could be internal to the compiler binary, or inside some
> > library, or whatever.
> > How gcc implements the fn is entirely up to it.
> >[/color]
>
> Sure, but it was just curiosity. I don't need it. No one ever will. ;)
> It was just to understand how the atoi() function was implemented :D[/color]
a_toi does what atoi does, for valid arguments.
int a_toi(const char *nptr)
{
int n;
n = 0;
while (isspace(*nptr) ) {
++nptr;
}
if (*nptr != '-') {
if (*nptr == '+') {
++nptr;
}
while (isdigit(*nptr) ) {
n = 10 * n - '0' + *nptr++;
}
} else {
++nptr;
while (isdigit(*nptr) ) {
n = 10 * n + '0' - *nptr++;
}
}
return n;
}
--
pete
David Paleino wrote:[color=blue]
>
> Mark McIntyre ha scritto:[color=green]
> > On Fri, 03 Mar 2006 12:22:32 +0100, in comp.lang.c , David Paleino
> > <d.paleino@gmai l.com> wrote:
> >
> >[color=darkred]
> >>Yes, I'm using gcc, the problem is that I can't really find it:[/color]
> >
> >
> > You really don't need to.
> >
> >[color=darkred]
> >>As you can see, at least in /usr/include, there isn't a single
> >>definition for __strtol_intern al.[/color]
> >
> >
> > *shrug*. It could be internal to the compiler binary, or inside some
> > library, or whatever.
> > How gcc implements the fn is entirely up to it.
> >[/color]
>
> Sure, but it was just curiosity. I don't need it. No one ever will. ;)
> It was just to understand how the atoi() function was implemented :D[/color]
a_toi does what atoi does, for valid arguments.
int a_toi(const char *nptr)
{
int n;
n = 0;
while (isspace(*nptr) ) {
++nptr;
}
if (*nptr != '-') {
if (*nptr == '+') {
++nptr;
}
while (isdigit(*nptr) ) {
n = 10 * n - '0' + *nptr++;
}
} else {
++nptr;
while (isdigit(*nptr) ) {
n = 10 * n + '0' - *nptr++;
}
}
return n;
}
--
pete
Comment