Solved

URGENt: Search and Store

Posted on 2003-10-22
6
183 Views
Last Modified: 2010-04-02
Hi
I have been able to read a text file . This text files contains information from separate channels ( Channel 1, Channel 2, and so on upto 20 channels ). Each row belongs to a separate channel and each row is made up of columns of data.
The data in "row one" it represents a specific "Channel"
It could be information from "Channel one" or could be information from "Channel two" or any other channel.
Now i have to store and present information as
Channel 1
Channel 2
Channel 3
..............
..............
and so on .

The only way i can get to know which is channel one is by " reading through a line and find " three alphabets corresponding to that channel e.g. " if row one contains X, Y, Z it is channel 1, if it is X,Z, Y it is channel 2  and so on.
I have only three alphabets to relate and find channel .

How do i write the search string for that ?
since i have been able to read and successfully store the data. Please guide me in the right direction.
Please bear in mind i am begineer and only a a few months in C++ and MFC . So please explain things  for a novice.

Thanks.
iCe
0
Comment
Question by:iceb
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9602314
Is there a specific way in which these 3 characters are laid out? Can you give a demonstration of this?
0
 
LVL 1

Author Comment

by:iceb
ID: 9602420
Sorry my fault.
It is of the format shown below
S.No.      Channel Name        alphabet1      alphabet 2    alphabet 3
1   ,         blah                ,           x          ,          y       ,             z
2   ,         trash               ,           y          ,          x       ,             z
3   ,         grin                 ,           x          ,                  ,             y                    
4
5
6
...............
................

The file is separated by commas. There might be cases that the alphabet is missing as shown in second line.

Thanks for reply.
I hope that makes it a little more clearer.

.iCe.
0
 
LVL 3

Expert Comment

by:gkatz
ID: 9602463
does this have to be done in C++, other languages are made for this such as Perl or any other language with regular expressions.

-gkatz
0
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.

 
LVL 4

Accepted Solution

by:
n_fortynine earned 500 total points
ID: 9602479
You can use a map to do this. Each element in a map is a pair of data.
for example:
#include <map>
map<string, string> ChannelMap;
You can use the first item to hold the string denoting the channel and the second the channel name. Adding an entry to a map is like this (for example):
string x = map("xyz");
map("xyz") = "blah";
//if there is a missing letter you can use a space I guess"x y"?
to search a map, you can write a simple loop as follow:
  //say
  string searchString = "blah";
  for(map::const_interator CI = ChannelMap.begin(); CI != ChannelMap.end(); CI++)
  {
     if(CI->first == searchString) cout <<CI->second << endl;
  }

Will this structure help?
0
 
LVL 1

Author Comment

by:iceb
ID: 9602754
!@#$%^&*() Confusion and more confusion.
Thats the state of my mind !
thanks for replying neways.
Yes plz it has to be done in C++ .
As i am developing an application with GUI  . so i believe i can't use "cout. "
But i will try and let you know if it works.
i used "CArray" to store the data .  

Thanks.

.iCe.

0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9602937
>>As i am developing an application with GUI  . so i believe i can't use "cout. "
>>But i will try and let you know if it works.

That's just an example of how to search for values in a map :)
What I would do is to read the data from the file and put them in the map, then whenever I am given a channel's "code" I'll just search the map for the channel name. It's just convenient so that I don't have to write my own "array" structures.
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…
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…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

932 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

14 Experts available now in Live!

Get 1:1 Help Now