473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

extracting a report from files

Hi

I would appreciate any idea on how to approach this task.
I have files which look like this:

file1
men 234
women 112
children 4
cars 11
file2
men 344
children 34
dogs 9

....

I need to print a report of all the data in the files which look like
this.

files men women chidden cars dogs

file1 234 112 4 11 0
file2 344 0 34 0 9

that is a table with fields names are columns and file names are
rows, the columns name all possible categories in the files, raw names
the files, a zero where there is no data for that particular field in
any given file.

I was thinking, open files, read data into a map, iterate through the
map, depending on the key, place the value in vector so that we have
vector for men, and another for women,... with the size of "number of
files", then foreach vector<category(foreach vector<files>) cout
with setw(int) and so forth.

thanks
Aug 22 '06 #1
2 1392
Gary Wessle <ph****@yahoo.comwrote:
Hi

I would appreciate any idea on how to approach this task.
I have files which look like this:

file1
men 234
women 112
children 4
cars 11
file2
men 344
children 34
dogs 9

...

I need to print a report of all the data in the files which look like
this.

files men women chidden cars dogs

file1 234 112 4 11 0
file2 344 0 34 0 9

that is a table with fields names are columns and file names are
rows, the columns name all possible categories in the files, raw names
the files, a zero where there is no data for that particular field in
any given file.

I was thinking, open files, read data into a map, iterate through the
map, depending on the key, place the value in vector so that we have
vector for men, and another for women,... with the size of "number of
files", then foreach vector<category(foreach vector<files>) cout
with setw(int) and so forth.
I would do something like,

typedef std::map<std::string, intCategory;
std::map<std::string, Categoryfiles;

Then, once you fill it, you can access it like:

std::cout << files["file1"]["men"] << '\n';

Filling in the maps and converting this to use iterators is left as an
exercise.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Aug 22 '06 #2
"Gary Wessle" <ph****@yahoo.comwrote in message
news:87************@yahoo.com...
Hi

I would appreciate any idea on how to approach this task.
I have files which look like this:

file1
men 234
women 112
children 4
cars 11
file2
men 344
children 34
dogs 9

...

I need to print a report of all the data in the files which look like
this.

files men women chidden cars dogs

file1 234 112 4 11 0
file2 344 0 34 0 9

that is a table with fields names are columns and file names are
rows, the columns name all possible categories in the files, raw names
the files, a zero where there is no data for that particular field in
any given file.

I was thinking, open files, read data into a map, iterate through the
map, depending on the key, place the value in vector so that we have
vector for men, and another for women,... with the size of "number of
files", then foreach vector<category(foreach vector<files>) cout
with setw(int) and so forth.
Your way sounds about as good as any other. This could be done a few
different ways, but I see nothing wrong with the way you plan on going about
it.

One thing I might add, though, is I might also use a set that just contained
the key names (men, women, etc..).

Read a file, read the key and the value. Place the Key into a set. Place
the key and value into a map (a vector of maps so you could read however
many files).

When you are finished processing files, iterate through the map outputing
the keys (so you get your files, men, women, children, cars, dogs, etc..).
Then iteratore through the set for each map in the vector finding each key
and outputing the value, 0 if it is not found.
Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Nazgul | last post by:
Hi! I want to implement a small tool in Python for distributing "patches" and I need Your advice. This application should be able to package all files chosen by a user into a self-extracting.exe...
2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
1
by: v0lcan0 | last post by:
Any help on extracting the time part from the datetime field in SQL database. even though i had entered only the time part in the database when i extract the field it gives me only the date...
0
by: Nadav | last post by:
Hi, Introduction: *************************** I am using the MSI API to extract MSI embedded files, I do this by iterating through all of the records in the ‘_Streams’ table and dumping...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
2
by: Robert McEuen | last post by:
Sorry if this double-posts...Google doesn't do a very good job of communicating whether something has posted or not. Using Access 97, WindowsXP Is there a way to pass command line parameters...
2
by: bjm | last post by:
I created a self extracting zip file with about 9000 files in it. I extracted it manually from the command line without a problem. However, when I tried to do the same extraction at the same...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
4
by: Ant | last post by:
Hi all, My kids have a bunch of games that have to be run from CD (on Windows XP). Now they're not very careful with them, and so I have a plan. I've downloaded a utility (Daemon Tools) which...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.