|
p[0] = 0 sets the first character to NULL. The rest is just wasteful fluff. It's bad form because it shows coding out of habit, not by deliberate thought.
DavidCrow wrote: One word does this to you
Yes.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
You heard very few thing in you life, I suppose. I guess you're very young.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
"one of"
"one of"
"one of"
sigh
Yeah, I'm young. Compared to my father. (Been around too long, actually, and have long run out of patience for weird code habits that do nothing but chew up CPU cycles and which require more typing than that which is necessary.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
There's nothing bad in initializing a buffer. At least it's useless. But it is also harmless.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
zakkas2483 wrote: _tcscat( lptMessage, L"TEMP::" );
Try changing that to
_tcscpy( lptMessage, L"TEMP::" );
so you initialise lptMessage properly without relying on its previous content.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
To be pedantic, this should be wcscpy(lptMessage, L"TEMP::"); (else use the _T() macro)
(Of course to be even more pedantic, why he's allocating local buffers 25 characters long instead of just using a simple array such as wchar_t message[25]; is senseless. Unless he's controlling the lengths of the strings elsewhere, he should also be using the wcscpy_s and wcscat_s .)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
You're quite right - I did mean to point that out (honest!).
Joe Woodbury wrote: (Of course to be even more pedantic, why he's allocating local buffers 25 characters long instead of just using a simple array such as wchar_t message[25]; is senseless. Unless he's controlling the lengths of the strings elsewhere, he should also be using the wcscpy_s and wcscat_s.)
I'm always tempted to say "why don't you just use a string class?!?!". CString or std::string, they both make simple string manipulation a hell of a lot easier.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: I'm always tempted to say "why don't you just use a string class?!?!". CString or std::string, they both make simple string manipulation a hell of a lot easier.
I agree, but I assume he was doing some assignment which prohibited such.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
No.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Are you using C or C++ ? If you are using C++, I suggest you use new instead of malloc.
For instance:
LPTSTR lptSub = new TCHAR[25];
LPTSTR lptMessage = new TCHAR[256];
_tcscat( lptMessage, lptSub );
Be carefull that when you call _tcscat, your strings should contain something (and not garbage). OTherwise the result will be a big mess .
|
|
|
|
|
Thanks but ...
I am having strange problem.
PTSTR lptSub = new TCHAR[25];
LPTSTR lptMessage = new TCHAR[256];
somefun(lptSub);
MessageBox(NULL,lptSub,L"ABC",1);
///Above line display result perfectly
// Do something with the strings
_tcscat( lptMessage, L"TEMP::" );
_tcscat( lptMessage, lptSub );
MessageBox(NULL,lptMessage,L"ABC",1);
///Above line display only TEMP::
I am getting why???
|
|
|
|
|
zakkas2483 wrote: // Do something with the strings
_tcscat( lptMessage, L"TEMP::" );
_tcscat( lptMessage, lptSub )
I suppose you should pass explicitely the lenght of the buffer, since you've allocated dinamically it.
Side note, you should always check the return value of the new operator.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thanks but ...
I am having strange problem.
PTSTR lptSub = NULL;
lptSub = new TCHAR[25];
if( lptSub == NULL )
return;
LPTSTR lptMessage =NULL;
lptMessage= new TCHAR[256];
if( !lptMessage )
return;
somefun(lptSub);
MessageBox(NULL,lptSub,L"ABC",1);
///Above line display result perfectly
// Do something with the strings
_tcscat( lptMessage, L"TEMP::" );
_tcscat( lptMessage, lptSub );
MessageBox(NULL,lptMessage,L"ABC",1);
///Above line display only TEMP::
still having problem with above code.
|
|
|
|
|
zakkas2483 wrote: somefun(lptSub);
MessageBox(NULL,lptSub,L"ABC",1);
Is it displaying the right string? Can you show me the "somefun" code?
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
|
|
|
|
|
Thank you everybody. i did one mistake in my code while copying the in to lptMessage.
And sorry for taking your valuable time.
|
|
|
|
|
zakkas2483 wrote: _tcscat( lptMessage, L"TEMP::" );
_tcscat( lptMessage, lptSub );
Why didn't you change it to
_tcscat( lptMessage, 256, L"TEMP::" );
_tcscat( lptMessage, 256, lptSub );
as I've suggested?
Sorry, I've confused _tcscat , with the secure cousin, as Hey Joe pointed out. Sorry again.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, March 27, 2009 1:17 PM
|
|
|
|
|
Because your code makes absolutely no sense. It won't even compile. Furthermore, you are mixing the "_t..." prefix with an L"", instead of a _T() macro. Perhaps you meant to use wcscat_s ?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
My code? No sense? I challenge you to duel, Sir.
BTW: You're right on mixing _t with L on the other hand the code makes perfect sense.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I parry your thrust and counter with: since when does strcat() have three parameters?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
you're right indeed, my bad, I've confused it with the secure version . I'm sorry for the OP.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Can someone please tell me how to get the following to display the right binary display and not have the '1' show up at the end.
eg value (3 * 5) = 15 -> 1111
value (1 + 1) = 2 -> 1011 How do i stop it at 10.
If i change the 4 to 2 it works. If the calculations go back to 15. I don't get the 1111 only 11. What am I missing?
thanks a million
char string[64];
int value;
for (int bit = 0; bit < 4; bit++)
{
int mask = value >> bit;
if ((value & mask) == mask)
string[bit] = '1';
else
string[bit] = '0';
}
string[4] = '\0';
thanks a million
|
|
|
|
|
Why not just use _itoa or _ltoa with a radix of 2?
|
|
|
|
|
Yes that works. when the calculation results in a smaller number.
I change my int to _int64 and i get a 0 in the output obviously with some compile warnings about loss of data.
Is there an identical function for int64.
thanks a million.
|
|
|
|
|