|
Garth,
Thanks, this is perfect! What is CP though? I would like to explore other solutions too.
Robert
|
|
|
|
|
|
I have to convert some integers into hexadecimal string format and then convert them back in later process, there's no problem until I encountered negative integers then things messed up:
int nOffset = -2600;
TCHAR sz[32] = _T("");
_stprintf(sz, _T("%X"), nOffset);
nOffset = _tcstol(sz, NULL, 16); And the value of nOffset becomes 2147483647, not -2600 as I expected.
How can I solve this problem? Thanks.
|
|
|
|
|
use _tcstoul() instead of _tcstol()
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you man! I can't believe how lame I was...
|
|
|
|
|
I think the format converts it to unsigned long by default anyways. The large number is just how a negative number is expressed. It is (0xFFFFFFFF - 2600). If you want it to act as needed you must do it yourself:
_stprintf(sz, _T("%s%X"), (nOffset < 0 ? _T("-") : "", <br />
(nOffset < 0 ? -nOffset : nOffset);
J.
----------------------------
|
|
|
|
|
Thank you for the reply, but I have to make sure that the result string does not exceed 8 characters long, so the "-" cannot be added. I used PJ Arends's method and it worked perfectly. Thanks again.
|
|
|
|
|
I need this in c++ console.
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Searching where ? The command line ? Text input ? A file ? The cracks in the floor ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I want to open a file, text, and look for a specific character, ' ; '. Also I would like to see how many lines were before the actual character. Please help me in any of the above problems.
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Sounds like you are writing a C compiler...
Maxwell Chen
|
|
|
|
|
no not really, im doing a real AI program that learns tic tac toe from nothing, please help me. confused:
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Read my article on extending iostreams to write a custom stream. I'd impliment a stream that derives from fstream, and add behaviour to count newlines and stop on a ;
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
This may be of some help.
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] = "This is a sample string";
char key[] = "aeiou";
char * pch;
printf ("Vowels in '%s': ",str);
pch = strpbrk (str, key);
while (pch != NULL)
{
printf ("%c " , *pch);
pch = strpbrk (pch+1,key);
}
printf ("\n");
return 0;
}
Output:
Vowels in 'This is a sample string': i i a a e i
Thank You
Bo Hunter
|
|
|
|
|
Hey, cool. A C programmer. Is there much work in C still ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How would you go about developing an algorithm that would for
example takes a list of songs and shuffles them and uses each
song once and only once? Also what if you wanted to me aware
of the order so that you could have a previous function that
would give you the previous song in the list back to the
beginning?
Thanks,
Steve
|
|
|
|
|
This is not optimal, but it can serve your purposes:- Let
n be the number of songs to shuffle.
- Define a map of
int s to string s.
- For every song in the list:
- Generate a random number
r between 0 and n-1 , check if the r -th entry of the map is empty, repeat until you find an empty slot.
- Insert the song into the map using index
r
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for your responses. I will look into Mr. Dunn's comment as well.
Steve
|
|
|
|
|
I recommend you rather follow Mr Dunn's comment, it is a much cleaner solution. Somehow I forgot about std::random_shuffle .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
I recommend you rather follow Mr Dunn's comment, it is a much cleaner solution. Somehow I forgot about std::random_shuffle.
Muchas gracias tio.
Steve
|
|
|
|
|
|
Has anybody been able to build the Boost library for MS Visual C++ 6.0. I have downloaded Boostjam and followed all the instructions on getting the library built but I don't get any *.lib files in the end, just .CMD files.
Can anybody help?
I am the handsome one in the crowd.
|
|
|
|
|
I guess you might get more helpful response at the Boost Users mailing list[^].
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have been drawing a dialog box with CDC class. How do I clear what I have drawn to the dialog box?
|
|
|
|
|
With RedrawWindow maybe?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|