TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JO GERAERTS
from: TOM TORFS
date: 1998-03-29 14:32:00
subject: convert char to int...

Jo Geraerts wrote in a message 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])
Be aware that str[2] can only store 1 character + NUL terminator.
 JG> But the value is a number is an I want to convert it to a integer.
 JG> How can I do that. I tried this:
 JG> int x=(int)str;
Something similar to that _may_ be possible if you use a string class that 
overloads the assignment operator.
However, you can always use this solution:
#include 
int x = atoi(str);
(atoi stands for ASCII-to-integer)
greetings,
Tom
tomtorfs@village.uunet.be
--- timEd/2 1.10+
---------------
* Origin: 80X86 BBS 32-15-24.62.32 V.34/V.FC (24h/24h) (2:292/516)

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