Solved

Parsing a line

Posted on 2003-11-29
5
260 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
[X]
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
  • 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

Industry Leaders: 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!

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

626 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