I would like to acquire data from a USB device. The device
send to PC data in strings like "0xa0 oxa1 oxa2...". I should
have to :
1,searching in the strings and pick up useful data like "0xa1",
"0xa2" and so so.
2,convert them from Hex data to decimal data.
3,save to a array.
How could I do it?
I am a new commer. I often find that I can't find the right place
in MSDN for the questions. Would you tell me how to use MSDN for
the above questions?
Jochen Kalmbach [MVP] - 18 Jul 2005 12:20 GMT
Hi yinyz!
> I would like to acquire data from a USB device. The device
> send to PC data in strings like "0xa0 oxa1 oxa2...". I should
[quoted text clipped - 4 lines]
> 2,convert them from Hex data to decimal data.
> 3,save to a array.
1. Use "strtok" to separate the string
2. Use strtol(..., 16) to convert to int
3. Store it in an int-array or std::vector<int>

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Hendrik Schober - 20 Jul 2005 11:03 GMT
> I would like to acquire data from a USB device. The device
> send to PC data in strings like "0xa0 oxa1 oxa2...". I should
[quoted text clipped - 6 lines]
>
> How could I do it?
You could use string streams:
#include <sstream>
//...
std::vector<int> result;
std::istringstream iss("0xa0 0xa1 0xa2");
for(;;) {
int i;
iss >> std::hex >> i;
if( !iss.good() ) break;
result.push_back(i);
}
if( !iss.eof() ) error();
//...
> I am a new commer. I often find that I can't find the right place
> in MSDN for the questions. Would you tell me how to use MSDN for
> the above questions?
I don't think you'll find an explanation
for the above in the MSDN lib. It's a
reference, not a text book.
Schobi

Signature
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org
"Coming back to where you started is not the same as never leaving"
Terry Pratchett