Hi, I want to split a char string.

We can use “strtok” function for split a string by using token. But in my problem, there is no specific separation/token between each value. The data directly come from an external device through the serial port. I used “ReadFile” function to read and buffer data from serial port. Finally I print buffer to display data. But my data is not correct format. That is like below.

<<CC>314.41778E-22.93253E+13.39812E+20.00000E+00.00000E+01.00000E+01.00000E+02.74760E-10.00000E+03.20000E+10.00000E+00.00000E+00.00000E+01.00000E+01.00000E+01.00000E+00.00000E+03.20000E+10.00000E+00.00000E+00.00000E+01.00000E+01.00000E+01.00000E+02.96000E+22.96000E+20.00000E+0256104.66418E-22.96000E+21.02300E+01.61743E+0-4.88280E-3-3.97245E-22.47061E+03.23730E+14.99510E+19.88542E-1-1.22070E-220101CD2B<E>>

I think, "ReadFile" function capture and buffer all data at one time, which come to serial port. If I could capture, buffer and display one by one, then may possible to separate each value. But I don´t know how to do it. Or may be I am wrong.
Actually, I want to convert it as like below format:
<<CC>
31
4.41778E-2
2.93253E+1
3.39812E+2
0.00000E+0
0.00000E+0
1.00000E+0
1.00000E+0
2.74760E-1
0.00000E+0
3.20000E+1
0.00000E+0
0.00000E+0
0.00000E+0
1.00000E+0
1.00000E+0
1.00000E+0
0.00000E+0
3.20000E+1
0.00000E+0
0.00000E+0
0.00000E+0
1.00000E+0
1.00000E+0
1.00000E+0
2.96000E+2
2.96000E+2
0.00000E+0
256
1
0
4.66418E-2
2.96000E+2
1.02300E+0
1.61743E+0
-4.88280E-3
-3.97245E-2
2.47061E+0
3.23730E+1
4.99510E+1
9.88542E-1
-1.22070E-2
2
0
101
CD2B<E>>

Anybody could give me some idea, how can I split the string.
Notes: I’m using MS Visual Studio 2008.

Thanks

there is no specific separation/token between each value. The data directly come from an external device through the serial port.

Bingo, without a delimiter you're basically fubar'd

Yeh, it wont work. For example in the very first part, you want to change this:
314.41778E-2 to 31 and 4.41778E-2
However it could also be:
3 and 14.41778E-2 or just 314.41778E-2

So AFAIK, it's impossible unless you have have some way of knowing where the number starts or ends.

Edited 7 Years Ago by William Hemsworth: n/a

So, you told, it is not possible to split as my requirement. is it possible to separate when it retrieve data from serial port (when it call "ReadFile" function)?

There's only one way you're gonna get this to work.

And that is to get your hardware device to spit out the data with a delimiter.

How you do that is irrelevant in terms of c/c++.

This article has been dead for over six months. Start a new discussion instead.