TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JO GERAERTS
from: AUKE REITSMA
date: 1998-03-27 21:43:00
subject: convert char to int...

Hi Jo,
On 16 Mar 98, 17:35, you wrote to All
 JG> In a program I want to use a ini file. I've got a predefined
 JG> function that reads the value and stores it in a string (char
 JG> str[2]) But the value is a number is an I want to convert it to a
 JG> integer. How can I do that. I tried this:
 JG> int x=(int)str;
 JG> I also tried this:
 JG> int x=(int)*str
These kinds of conversions must be done explicitly by a function. NOT by a 
cast. E.g.:
    int x = atoi( your_string_value );
BTW: your string array is probably too small. The array str[2] can hold only 
a single digit in addition to the terminating ascii nul character.
BTW2: You may wish to read the C_echo in addition to C_plusplus.
Greetings from
 _____
 /_|__|  Auke Reitsma, Delft, The Netherlands.
/  | \  --------------------------------------
--- GEcho 1.00
---------------
* Origin: Home by the C (Auke.Reitsma@net.hcc.nl) (2:281/400.20)

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™.