Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Parsing a line

How do parse something like this?
There is “:” between first number and second number and “,” for the rest.


3:  1,  4,  5, 10, 14, 15, 16, 19, 22, 25, 26, 37, 38, 42, 50, 56, 62, 70, 74, 80
1:  6, 12, 27, 28, 29, 30, 33, 36, 37, 39, 41, 43, 46, 49, 56, 57, 59, 62, 73, 80
….
...
...
...
0
dkim18
Asked:
dkim18
  • 3
  • 2
1 Solution
 
DanRollinsCommented:
What are you doing with this data?  Are you programming for Unix, or can you use MFC classes?

You have asked three very similar questions, but you do not respond when an Expert posts a comment.  Please respond.  Thanks!

The short answer is:
1. Get a pointer to the string.  

2. Advance the pointer until it points to a colon (':').  Save everything up to the colon.  That is (probably) the 'key' to the line  [I could say more if you would describe what you are doing... and specifically, why you are doing it]

3.  Now the rest of the string is a seies of numeric values.  You can treat them as strings or you can convert them to binary int values.  That will of course, depend upon what you are doing... and specifically, why you are doing it.

4.  You can manually move the pointer forward to get to the comma, or you can use the std library function such as strtok.

5.  When you hit the end of the line, go to step 1 and parse the next line.

-- Dan
0
 
dkim18Author Commented:
I am trying to analyze keno output data. So the first number is bonus number and the rest are random numbers and each line is one game. From this data file, I am trying calculate the top 5 numbers in order from most occurrences with their occurrence frequency(%), and the bottom 5 numbers in order from least occurrences with their occurrence frequency(%).

Thank you your help

P.S.
I am trying compile test.cpp file in my mandrake OS, but “g++” or “gcc” command doesn’t recognized. (I have an error something like command not found.) Is that mean I have not installed c++ compiler when I install mandrake? Isn’t that default option when I install mandrake?
0
 
DanRollinsCommented:
sorry, I don't do mandrake.  

If you are having trouble compiling a program, then that is your first challenge.  Write and successfully compile and successfully execute a program that prints "Hello World" on your screen.  When you are done, report back here and we can move forward.

-- Dan
0
 
dkim18Author Commented:
I am using Solaris and the test.cpp works now.

In order to complete, above to analyze keno output data, I wll create array size of 80 and read the file and increment each element during run time.
When my program reads the each line, how does ifstream ignore “,” or “:”?
0
 
DanRollinsCommented:
Use strtok, as I have described in one of your many other related questions:
     http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20813330.html

Instead of using cout to display the values, put them into an array.

-- Dan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now