Map - printing all elements - why?


 
Thread Tools Search this Thread
Top Forums Programming Map - printing all elements - why?
# 1  
Old 04-14-2008
Map - printing all elements - why?

Hi All
I have written a map program. The program is simple

I have the input file input.dat which has the following
Code:
BLACK 000180 TECH1
BLUE   000340 TECH2

I want to map
a[BLACK]=first row ie Black 000180 and TECH1
a[BLUE ]=second row i.e BLUE 000340 and TECH2
Code:
struct CHAR
{
	char chr[5];
	char val[5];
	char code[6];
};

multimap<string , CHAR> names;
int main()
{
char temp1[1024];
struct CHAR ch;
memset(temp1,0x00,1024);
FILE *IF1;
string S;
char *ptr;
IF1=fopen("input.dat","r");

while (fgets(temp1,1024,IF1) != NULL)
{
       ptr=temp1;
	 for(;*(ptr) != '\n';ptr=ptr+41)
     {
         s   trncpy(ch.chr,ptr,5);
	   strncpy(ch.code,ptr+5,6);
	   strncpy(ch.code+11,5);
	   S=ch.chr_name;
	   names.insert(multimap<string,CHAR>::value_type(S,ch));
    }

}
multimap<string, CHAR>::iterator p;
for(p=names.begin();p!=names.end();p++)
	 cout<<p->second.chr<<endl;

}

While running the above program the output is
the whole file

BLACK 000180 TECH1
BLUE 000340 TECH2

I don;t understand when i want to print second.chr alone why it prints all?

Can any one help?

Regards
Dhanamurthy

Last edited by Yogesh Sawant; 04-14-2008 at 02:22 PM.. Reason: added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing array elements in reverse

Hello Experts, I am trying to print an array in reverse. Input : 1. Number of array elements 2. The array. Eg: 4 1 2 3 4 Expected Output (elements separated by a space) : 4 3 2 1 My Code : (6 Replies)
Discussion started by: H squared
6 Replies

2. Programming

Map Question C++

Hello All, I am having an issue of putting a Boolean value in the maps as the 3rd parameter. Something like the following : int value; std::map<String str, int x, bool bl> where bool returns false if x>value else true. All I see in the map examples is that I can add the... (2 Replies)
Discussion started by: mind@work
2 Replies

3. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

4. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

5. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

6. Shell Programming and Scripting

printing keys only using map

Hello everyone, Can anyone give me a suggestion on lines below: %hash = map {($_, -M "$dir/$_")} readdir D; print map "$_\n", sort values %hash; The thing is this will print the floating point numbers of files recently created/modified. I'd like to print out the file names only while... (0 Replies)
Discussion started by: new bie
0 Replies

7. Shell Programming and Scripting

printing array elements inside AWK

i just want to dump my array and see if it contains the values i am expecting. It should print as follows, ignore=345fht ignore=rthfg56 . . . ignore=49568g Here is the code. Is this even possible to do? please help termReport.pl < $4 | dos2ux | head -2000 | awk ' BEGIN... (0 Replies)
Discussion started by: usustarr
0 Replies

8. UNIX for Advanced & Expert Users

map comparsion

Hi all I have to compare maps/files on two seperate boxes and the output must be as following: 1)list the maps/file on box1 2)list the maps/file on box2 3)List maps in both the environments a) which are same b)which are different pls any ideas are appreciated thnks (2 Replies)
Discussion started by: bkan77
2 Replies

9. UNIX for Dummies Questions & Answers

Unix map?

There is a "Map"? of Unix and all its varients somewhere on the net. I used to have the link , but can't find it now. Anyone out there have a clue???? A good magician never reveals his secret; the unbelievable trick becomes simple and obvious once it is explained. So too with... (3 Replies)
Discussion started by: Bodhi
3 Replies

10. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies
Login or Register to Ask a Question