Solved

Parsing a line

Posted on 2003-11-29
5
224 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

747 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

12 Experts available now in Live!

Get 1:1 Help Now