|
Thank you DavidCrow!
What do you mean SetEndOfFile()? Is there a method called SetEndOfFile() in C?
regards,
George
|
|
|
|
|
George_George wrote: Is there a method called SetEndOfFile() in C?
There's a function called SetEndOfFile().
"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
|
|
|
|
|
Thank you DavidCrow!
Why my method is better than SetEndOfFile()?
regards,
George
|
|
|
|
|
George_George wrote: Why my method is better than SetEndOfFile()?
You wanted portability, didn't you?
"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
|
|
|
|
|
Thank you DavidCrow!
Yes, I mean why SetEndOfFile() has worse portability?
regards,
George
|
|
|
|
|
George_George wrote: ...why SetEndOfFile() has worse portability?
It's only for a Windows platform.
"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
|
|
|
|
|
Thank you DavidCrow!
regards,
George
|
|
|
|
|
There's two ways to get portability; the first is to use a common API and test it enough to make sure it works the same way on both systems; the second is to do such:
int main(int argc, char** argv)
{
#if defined(WINDOWS)
#elif defined(LINUX)
#endif
return 0;
}
The former tends to make for much more readable code... at least IMO.
earl
|
|
|
|
|
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
|
|
|
|