|
Thank you earl!
Your sample is only the general principle to develop portable code. In my case, to set the length of a file, is my method showed above has good portability? Do you have any better ideas or any comments?
regards,
George
|
|
|
|
|
Why do you need the file to be 100b?
I imagine your example should work, unless there are examples of sparse filesystems in use? I doubt it, but I don't keep up with the various file systems in use under linux.
Alternatively, you could just fwrite 100b of zeroes...
unsigned char buff[100];
memset(buff, 0x0, 100 * sizeof(unsigned char));
fwrite(buff, sizeof(unsigned char), 100, fp);
earl
|
|
|
|
|
Thank you earl!
Your method is using more memory compared with my method -- 100 more bytes for the local char array. Agree?
regards,
George
-- modified at 4:28 Wednesday 19th July, 2006
|
|
|
|
|
Sure, but who cares? As written it'll be allocated on the stack and disappear after the function is finished. You also could call fwrite 100 times on a single byte, if you're working in a space where 100b matters.
earl
|
|
|
|
|
Thank you earl!
regards,
George
|
|
|
|
|
Hi,
I have declared an integer type variable for an edit box.My requirement is I want the edit box to be left blank i.e there should be no "0" when it is displayed.How can this be done?
Thanks in advance
Sandhya
|
|
|
|
|
Before showing the Edit Control set its window text to null.
that is, if you are using dialog based application then in OnInitDialog() use the below statement;
GetDlgItem(EditCtrlID)->SetWindowText("");
or
if you have a control variable say m_editctrl then
m_editctrl.SetWindowText("");
Do your Duty and Don't expect the Result
|
|
|
|
|
SetDlgItemText (IDC_MYEDIT,"");
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
i forget the SetDlgItemText(..).
This will be more appropriate than SetWindowText():->
Do your Duty and Don't expect the Result
|
|
|
|
|
SetWindowText() is still good . dont worry .
|
|
|
|
|
Hi,
Please can u say How can we convert CString variable to char data type.
Thanks in advance,
tejaswini
|
|
|
|
|
<br />
char myCharVar[20];<br />
CString myStrVar;<br />
<br />
myStrVar = "This will be copied";<br />
myCharVar = myStrVar.GetBuffer(myStrVar.GetLength());<br />
You have an apple and me too. We exchange those and We have an apple each.
You have an idea and me too. We exchange those and We have two ideas each.
|
|
|
|
|
if your application is not based on _UNICODE text then you can use CString.GetBuffer(). this will return the starting address of the string.
other wise store this CString value in stl string, and covert as mentioned
#include string //use angular brackets
using namespace std;
CString str;
string strTemp((LPCTSTR)str);
char szValue[..] = {0};
strcpy(szValue, strTemp.c_str());
Do your Duty and Don't expect the Result
-- modified at 5:55 Monday 17th July, 2006
|
|
|
|
|
Parthi_appu wrote: strcpy(szValue, strTemp.c_str());
This is hardly necessary. Use:
strcpy(szValue, str);
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I think you have some member function like operator LPCTSTR() which returns const char *.
modified : which is a member function of CString class.
Regards
Abhishake Lahare
-- modified at 5:52 Monday 17th July, 2006
|
|
|
|
|
LPCTSTR() will return const TCHAR*.
if the application is UNICODE based then TCHAR* will be WCHAR*
Do your Duty and Don't expect the Result
|
|
|
|
|
tejaswini.g wrote: CString variable to char data type.
First of All, Char or Char*......?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Or see here
<br />
char *test;<br />
CString String;<br />
<br />
String="This is a test";<br />
test = new char[String.GetLength() + 1];<br />
strcpy(test , String); <br />
<br />
whitesky
|
|
|
|
|
Hi Whitesky
In the sample also mention the delete statement, it'll be useful to new C++ programmers.
Do your Duty and Don't expect the Result
|
|
|
|
|
One of the major selling points of using CString is so that new and delete won't have to be used. Some folks still continue to use/suggest them, however.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i mentioned it for char*, not for CString..
and personally i have bad experience while using CString..
so i'm avoiding CString class nowdays
Do your Duty and Don't expect the Result
|
|
|
|
|
Parthi_appu wrote: i mentioned it for char*, not for CString..
But it was in response to a post that was using CString . I was merely pointing out that new and delete are not necessary in that context.
Parthi_appu wrote: and personally i have bad experience while using CString..
so i'm avoiding CString class nowdays
Such as? I've been using it for 13+ years and have had no complaints with it. If used incorrectly, it could very well misbehave.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
that post contains the code..
char *test;
...
test = new char[String.GetLength()+1];
....
see the post which i replied for...
CString class works badly in some times, say GetLength() returns 0 if it has some string and IsEmpty() return TRUE if it has some string..
and using CString class is not that much difficult to misuse it...
Do your Duty and Don't expect the Result
|
|
|
|
|
Parthi_appu wrote: GetLength() returns 0 if it has some string and IsEmpty() return TRUE if it has some string..
I've never seen CString::GetLength() return 0 or CString::IsEmpty() return TRUE if the object was indeed non-empty. I just don't see it happening.
Parthi_appu wrote: CString class is not that much difficult to misuse it...
Anything for which you are not familar can be misused. With the exposure that CString has received since its incepton, to say it doesn't work in such trivial scenarios is just silly thinking.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
so u accept that i was not ask to delete the CString object..
surely CString will give problem while it was used in global thread methods...
i faced the above mentioned problems...
and also MSDN suggest to use ReleaseBuffer() after the use of GetBuffer(), i faced some memory problem when i tried to release the buffer..
and don't reply that i have to use the methods properly.. if u never face the problem then fine but i faced this problem.. for this particular reason i replaced all the CString to string in my application... and the problem is intermitent so their will be no chance of error in the code...
Do your Duty and Don't expect the Result
|
|
|
|