JG>In a program I want to use a ini file. I've got a predefined function that
JG>reads the value and stores it in a string (char str[2])
JG>But the value is a number is an I want to convert it to a integer. How can
I
JG>do that. I tried this:
JG>int x=(int)str;
JG>But if for example value=10 then x becomes something else. How can I
convert
JG>it without changing the value?
First of all 10 won't fit in a char[2] array - no place left for the
NULL.
to convert a string to an int use the
int atoi(const char*);
function. It's located in the STDLIB.H
PS The chars must be in the following order:
[WS] [SN] [ddd]
where
WS is white spaces
SN is a sighn
dddd number
eg.
"4"
"+3"
"-53"
" 3"
" +1"
Hope that helps :)
* SLMR 2.1a * It's only a hobby ... only a hobby ... only a
--- FMail 0.92
---------------
* Origin: The Programmer's Oasis on FIDONET! (1:348/203)
|