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

URGENt: Search and Store

Posted on 2003-10-22
6
185 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
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.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 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