|
Hi,
I am looking for a way to convert a double to the char representation, ie. put double, which is eight bytes, to char[8];
Example:
double nDb = 12.34;
char szDb[8];
szdB would hold the character representation of nDb which might look something like:
[0] 0''
[1] 0''
[2] 0''
[3] 0''
[4] 0''
[5] 0''
[6] 51'3'
[7] 64'@'
Thank you.
|
|
|
|
|
try snprintf
-c
Conservative:
One who admires radicals centuries after they're dead.
-- Leo C. Rosten
|
|
|
|
|
memcpy(szDb, &nDB, sizeof(double));
or, if you want to save keystrokes
(double & )szDb = nDb;
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
I call a modal dialog to input a number. The var that i added to the class has limits but these don't get checked until the calling (parent) dialog closes. Is there an option that I need to set or do i need to range ckeck on my own?
This is my call:
if(GetNumDlg.DoModal() == IDOK)
{
calleddialog = 0;
m_leftscale = atoi(GetNumDlg.m_numdisplayed);
UpdateData(FALSE);
//This will set the focus to another control to keep this dialog from popping up
//everytime focus returns
//
CEdit* pNextField = (CEdit*)GetDlgItem(IDOK); pNextField->SetFocus();
}
|
|
|
|
|
Can't you map your edit control to int variable with range validation? You can do this in ClassWizard.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
that is where I set the var up and I did use the range checking for it...just doest seem to check it until I try to exit the calling window.\thanks
|
|
|
|
|
I'm not really sure what exactly are you doing. In the code you've posted you have atoi call. This means that your dialog has string variable, not integer one.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
This is where the problem lies. This is a pop up number entry keyboard. I have two vars one is a string and the other is the integer. I use the string to create the number...make any sence?
|
|
|
|
|
Do you have range validation in GetNumDlg?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
calleddialog = 1;
if(GetNumDlg.DoModal() == IDOK)
{
calleddialog = 0;
m_rightscale = atoi(GetNumDlg.m_numdisplayed);
UpdateData(FALSE);
m_rightscale is where the value (int) is placed and returned to the edit box. This var is setup in the wizzard with a range. I'm thinking that I need another var in the getnumdlg to check the range on.
Thanks for the help...
|
|
|
|
|
GetNumDlg.m_numdisplayed seems to be string variable. Can't you just change that to integer with validation?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
It probably could be if I were to do the math to creat the next digit with each key entered. I went the easy route by just putting the key presses into a string. Thus if the user hits a 1, 3, 6 and a 9 I just put it in like 1369, then return it to the edit box as an int (atoi(1369)).
|
|
|
|
|
In the 'numeric' dialog, override DoDataExchange. Use atoi and check the range; if number doesn't satisfy your criteria display message box and call pDX->Fail().
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Hello,
I think what Tomasz Sowinski meant is that in the class wizard for the variable attached to the particular CEdit control in your dialog, you can select it to be an "int" or another number type (it defaults to CString). This saves a a world of extra work (like translating user string in to a number).
JennyP
|
|
|
|
|
The problem is I use this dialog in other places where I use different ranges. So I have to check the range after the user presses OK. So I'm creating the number as the user presses keys/buttons on this dialog and displaying it in an edit box so they can see the value. As they keys are pressed I create a string the corresponds to the order pressed. When it is over I return this to the calling dialog to process the number. So because of the way I do this I have no way to call the dialog again if the number is out of range. HMMMM?
I guess I'm just brain dead today. Thanks for the help
|
|
|
|
|
I found this in my code, and it works with no compiler or runtime error (so far). But I am thinking now it should have been delete[] a and not delete a . So why didnt it crash or complain?
char* a = new char [pDoc->m_KeysOptions.GetLength () + 1];
strcpy (a, pDoc->m_KeysOptions);
m_nToDisplay = pDoc->m_db.DLLSendKeywordsOptions(a);
delete a;
Thanks,
ns
Or should it really be delete a; after all?
|
|
|
|
|
|
It should be 'delete [] a'. Or, better yet, you should use CString or std::string.
Programs compiled with VC++ will not crash when you have an array of simple data types like char, double or int allocated with new and freed with delete without []. However, this is not guaranteed to work across all compilers/platforms.
The difference between 'delete x' and 'delete [] x' is that there are no destructor calls for elements of the array in the first version. Obviously, when you have char array, you don't need to call any d'tors. But with any non-trivial class you'd get into trouble.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
You're much better off using CString .
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
ns wrote:
Or should it really be delete a; after all?
Indeed it should.
If you are interested in the details (what is the exact difference between delete[] and delete and why is the compiler not able to detect if you use the wrong version), you may take a look at this forum message.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
to simplify the question, let me use an example:
i have a customer struct:
struct Cust
{
char name[20];
int ID;
};
i save huge custs to a file.
but the struct is a dynamic one, fields may be addd (i.e. int age) or deleted (i.e. delete field int ID) or changed (ie. char name from [20] to [50]).
'dynamic' means modify happens at run-time and very often. because there are lots data (impossible load all to memory), any change needs long time.
do u have idea to solve the problem for quick modify?
(i try stream but can't find useful tech)
thx
includeh10
|
|
|
|
|
Hello!
You could try and save the names or codes of the fields before you save the data inside them. Then, when you load the information from a file, you create a struct with the correct fields based upon the names/codes that you load for each struct.
For instance, you have one customer with this struct:
struct Customer
{
char name[20];
int age;
}
And another with this struct:
struct Customer
{
char name[50];
int ID;
int age;
}
When you save it to a file, your file could look like this:
Customer1
name:20;age
"customer name";27
Customer2
name:50;ID;age
"longer customer name";100T67;35
Hope that helps!
Sincerely,
Alexander Wiseman
Est melior esse quam videri
It is better to be than to seem
|
|
|
|
|
thx but modify or 'dynamic' is unknown in advance.
includeh10
|
|
|
|