Re: (part 5) Han from China answers your C questions
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Fri, 31 Oct 2008 04:14:46 +0000
Borked Pseudo Mailed <nobody@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 that this exhibits undefined behaviour (quite apart
from being silly). If the OP really needs to use atoi to do this
simple conversion, the easiest way would probably be:
a = atoi((char []){string[2], 0});
--
Ben.
.
- Follow-Ups:
- Re: (part 5) Han from China answers your C questions
- From: Peter Nilsson
- Re: (part 5) Han from China answers your C questions
- References:
- (part 5) Han from China answers your C questions
- From: Borked Pseudo Mailed
- (part 5) Han from China answers your C questions
- Prev by Date: Re: Han from China killfiles some people on CLC
- Next by Date: Re: floating point number help
- Previous by thread: (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
|