Re: (part 5) Han from China answers your C questions
- From: Peter Nilsson <airia@xxxxxxxxxxx>
- Date: Thu, 30 Oct 2008 22:01:09 -0700 (PDT)
Ben Bacarisse <ben.use...@xxxxxxxxx> wrote:
Borked Pseudo Mailed <nob...@xxxxxxxxxxxxxxxxx> writes:
a question abou "atoi" 66650...@xxxxxx said:
First,thanks for all who have answered my last question.
if char string[20]="12345";
how could I convert the string[2](that is "3") to an
int by using atoi? I only want to convert string[2],not
other string[i].
int a;
char string[20]="12345";
atoi((a=string[2]-'0',"X"));
The consensus is
"You don't vote for kings!"
- King Arther - Monty Python's Holy Grail
that this exhibits undefined behaviour
(quite apart from being silly).
Silly, yes, ub no. Note: atoi("X") produces 0. UB occurs
if (and only if) strtol(blah, 0, 10) would produce a value
outside the range of int.
If the OP really needs to use atoi to do this
simple conversion,
The OP doesn't, so why entertain the possibility? ;)
--
Peter
.
- Follow-Ups:
- Re: (part 5) Han from China answers your C questions
- From: Ben Bacarisse
- Re: (part 5) Han from China answers your C questions
- References:
- (part 5) Han from China answers your C questions
- From: Borked Pseudo Mailed
- Re: (part 5) Han from China answers your C questions
- From: Ben Bacarisse
- (part 5) Han from China answers your C questions
- Prev by Date: Re: floating point number help
- Next by Date: Re: floating point number help
- Previous by thread: Re: (part 5) Han from China answers your C questions
- Next by thread: Re: (part 5) Han from China answers your C questions
- Index(es):
Relevant Pages
|