Solved

Parsing a line

Posted on 2003-11-29
5
232 Views
Last Modified: 2010-04-01
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
Comment
Question by:dkim18
  • 3
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
ID: 9844994
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
 

Author Comment

by:dkim18
ID: 9845159
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9846680
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
 

Author Comment

by:dkim18
ID: 9851515
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9854653
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now