TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JO GERAERTS
from: ADAM MAJER
date: 1998-03-27 14:04:00
subject: convert char to int...

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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.