Re: (part 5) Han from China answers your C questions
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Fri, 31 Oct 2008 11:39:22 +0000
Peter Nilsson <airia@xxxxxxxxxxx> writes:
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.
Well I agree in that that has always been my reading of the matter. I
should have said that this has been debated.
--
Ben.
.
- 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
- Re: (part 5) Han from China answers your C questions
- From: Peter Nilsson
- (part 5) Han from China answers your C questions
- Prev by Date: Re: srand
- Next by Date: Re: Judge the encode systm used by the file.
- Previous by thread: Re: (part 5) Han from China answers your C questions
- Next by thread: Re: a question abou "atoi"
- Index(es):
Relevant Pages
|