|
kitty5 wrote: do you have to release the buffer right after getBuffer?
You release it as soon as you are done with it. However, since you are not modifying the CString object in your example, there's no need to call either method.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
kitty5 wrote: how do I assign the value of the CString input1 to a char*?
Why do you need to? What is it that the CString object is not doing that char* will?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: Why do you need to? What is it that the CString object is not doing that char* will?
You can't parse each char of the CString string like a char*...?
i.e. :
char *string = "0x2";
int cReturn = 0;
for(i = 2; i < nStringSize; i++)
{
cReturn = cReturn*16;
// Decode ASCII
if((string[i] >= '0') && (string[i] <= '9'))
cReturn += string[i] - '0';
else if((string[i] >= 'A') && (string[i] <= 'F'))
cReturn += string[i] - 'A' + 0xa;
else if((string[i] >= 'a') && (string[i] <= 'f'))
cReturn += string[i] - 'a' + 0xa;
else
// Incorrect character
return 0;
}
Kitty5
|
|
|
|
|
kitty5 wrote: You can't parse each char of the CString string like a char*...?
Sure you can. Just use either the GetAt() method or the [] operator.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You will save yourself a LOT of trouble by reading up on the CString class: MSDN.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
kitty5 wrote: // Check if the string starts with a '0x'
if(nStringSize > 2 && ('0' == string[0]) && (('x' == string[1]) || ('X' == string[1])))
{
for(i = 2; i < nStringSize; i++)
{
cReturn = cReturn*16;
// Decode ASCII
if((string[i] >= '0') && (string[i] <= '9'))
cReturn += string[i] - '0';
else if((string[i] >= 'A') && (string[i] <= 'F'))
cReturn += string[i] - 'A' + 0xa;
else if((string[i] >= 'a') && (string[i] <= 'f'))
cReturn += string[i] - 'a' + 0xa;
else
// Incorrect character
return 0;
}
return cReturn;
}
else return atol(string);
Why don't you save yourself a lot of grief and use strtol() instead?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
b/c atol's and strtol's parameter is const char*... not CString
Kitty5
-- modified at 15:33 Wednesday 21st June, 2006
|
|
|
|
|
Are you not familar with CString 's LPCTSTR() operator?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
How can i access(by iterating)list in the file, which is supplied dynamically(browsing to select file using CFileDialog)during the execution in vc++(mfc) project??
kamalesh
|
|
|
|
|
Use CFileDialog::GetPathName() to get the path of the file. Then open the file. Then read the data from the file.
|
|
|
|
|
ya i already used that.frm thre i can read only the 1st list.but iterating the list using Clist, it's not happening. can u tell me that? how to iterate in this file?
kamalesh
|
|
|
|
|
If you set the OFN_ALLOWMULTISELECT flag for the dialog, you use the following code to iterate through the list of path names:
CFileDialog dlg(...);
if (dlg.DoModal() == IDOK)<br />
{<br />
POSITION pos = dlg.GetStartPosition();<br />
while (NULL != pos)<br />
{<br />
CString newPath = dlg.GetNextPathName(pos);<br />
}
Is that what you are trying to do?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
-- modified at 15:29 Wednesday 21st June, 2006
|
|
|
|
|
kamalesh82 wrote: frm thre i can read only the 1st list
What list? Are you trying to read the contents of the selected file?
kamalesh82 wrote: ...but iterating the list using Clist...
How are you using CList ?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
and let me add...
|
|
|
|
|
if you want to read file and directory names with CListBox use DlgDirList
whitesky
|
|
|
|
|
I use function _gcvt() for convert the double value to string such as:
y = 0.01;
_gcvt(y,10,buffer);
MessageBox(buffer);
My problem is that the MessageBox will show "1.e-002".
How to do if want the string "0.01" after finish this function.
|
|
|
|
|
you could try doing a sprintf.
y = 0.01;
sprintf ( buffer, "%f", y );
|
|
|
|
|
Use
sprintf(buffer, "%f8.2", y); instead.
Best,
Jun
|
|
|
|
|
or see here
<br />
double y = 1230.01;<br />
CString strxx;<br />
strxx.Format("%lf", y );<br />
MessageBox(strxx);<br />
whitesky
|
|
|
|
|
Hi,
The below code for cfiledialog is have some problem. the problem is when i
press open many times the file dialog box opens ,but sometimes ( at any time ) when file dialog is open and if i press some starting character to select particular file ,the whole application closes automatically..
myclass::OnOpen() {
CFileDialog dlg(TRUE);
Sleep(50);
if (dlg.DoModal() == IDOK) {
l_strFileName = dlg.GetPathName();
MessageBox(l_strFileName);
filepath2 = (char *) (LPCTSTR) l_strFileName;
m_select.ShowWindow(SW_HIDE);
m_start.ShowWindow(SW_SHOW);
m_ed.SetWindowText(l_strFileName);
} }
Manjunath S
GESL
Bangalore
|
|
|
|
|
Manjunath S wrote: Sleep(50);
What's this for? A gratuitous Sleep() is usually an indication of something gone wrong.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi ,
If i remove sleep then also iam getting same error.
Manjunath S
GESL
Bangalore
|
|
|
|
|
Then you're giving the gratuity somewhere else.
|
|
|
|
|
can i get any sample code regarding ,to open fileopen dialog box
Manjunath S
GESL
Bangalore
|
|
|
|
|
Exactly what steps are you taking to reproduce the problem? Does it happen with every folder, or one in particular? What character are you typing? Is Enter/Return clicked? Does the same thing happen with GetOpenFileName() ?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|