Advertisement

String Manipulation Question

Started by August 26, 2000 01:13 PM
5 comments, last by Smack0007 24 years, 3 months ago
Ok, in the Win32 Enviroment, you can get two things from an Edit Box: a string, and an int (GetDlgItemText() & GetDlgItemInt()). How would you get a double or a float? Im pretty sure you have to do something like extract a string and convert it somehow but I have not been able to figure it out yet. zac@qisfl.net
Snowsoft Online
I don't pretend to know anything. Edited by - Smack0007 on 8/26/00 1:15:08 PM Edited by - Smack0007 on 8/26/00 1:16:23 PM
- I don't pretend to know anything.Snowsoft
if you can get a string of your number, all you need it the ATO family
Just look in your help files for the ato* functions.
atoi converts alpha to integer (hence the ATOI)
atof should convert from alpha to float, if I am not totally mistaken ?

youpla :-P
-----------------------------Sancte Isidore ora pro nobis !
Advertisement
I am going to try that, I think one of the main problems is that the GetDlgItemText() function puts the text into a LPTSTR. I need to convert that to a char somehow.

zac@qisfl.net
Snowsoft Online

I don't pretend to know anything.
- I don't pretend to know anything.Snowsoft
actually a "LPSTR" is the same thing as "const char *". long pointer to string which: a string is an array of char''s. which is the same thing as "char *". just explicitly cast it.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
I think I follow you, but could you give me a short example?

zac@qisfl.net
Snowsoft Online

I don't pretend to know anything.
- I don't pretend to know anything.Snowsoft
Someone please help me. Everytime I run this thing it crashes.

zac@qisfl.net
Snowsoft Online

I don't pretend to know anything.
- I don't pretend to know anything.Snowsoft
Advertisement
How r u doing the code?
I would do:

char * afloat;
float float;
int length;

//Can''t remeber off hand all the params to the functions
length= GetWindowTextLength(GetDlgItem(MAKEINTRESOURCE(TEXT_BOX))
//or sominthing, just get the length of the text
afloat = (char *)malloc(sizeof(char)*length+1));

GetDlgItemText(TEXT_BOX, afloat, length);
//once again can''t remeber params
afloat[length+1] = ''\0'';

float = atof(afloat);

//-------------------
Thats off the top of my head, and with out anything
to look up its acuracy.
Evan,
evan@achaia.dircon.co.uk

This topic is closed to new replies.

Advertisement