Solved

URGENt: Search and Store

Posted on 2003-10-22
6
192 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
[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
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
Technology Partners: 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!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

623 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