Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Parsing a line

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

856 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