|
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.
|
|
|
|
|
|
What about two calls to itoa ?
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]
|
|
|
|
|
FISH786 wrote: What am I missing?
Well, you need to know what the different operations do and how to use them when building your algorithm. This is a good exercise.
Some hints:
You are e.g. right shifting value by bit steps and put the result in mask . Unless bit equals zero, value and mask will most likely be different. Then you check if mask and value are the same....
It also looks like you're starting from the right (with the least significant bit) in value , but starts from the left in the string....
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Yes that was the idea. To make this work and look up how the operators and shifting works.
Thanks for your help.
|
|
|
|
|
do you mean this
int bit;
for ( bit = 0; bit < 4; bit++)
{
string[3-bit] = '0' + (value & 1);
value >>= 1;
}
string[bit] = '\0';
?
However the above code generates 0010 when value=2 .
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]
|
|
|
|
|
CPallini wrote: However the above code generates 0010 when value=2
What's wrong with that?
|
|
|
|
|
It is not wrong, of course...
Anyway he may prefer 10 instead of 0010 .
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]
|
|
|
|
|