Sponsored Content
Top Forums Programming Map - printing all elements - why? Post 302185211 by dhanamurthy on Monday 14th of April 2008 01:19:27 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
PKOPEN(3)						     Library Functions Manual							 PKOPEN(3)

NAME
pkopen, pkclose, pkread, pkwrite, pkfail - packet driver simulator SYNOPSIS
char *pkopen(fd) pkclose(ptr) char *ptr; pkread(ptr, buffer, count) char *ptr, *buffer; pkwrite(ptr, buffer, count) char *ptr, *buffer; pkfail() DESCRIPTION
These routines are a user-level implementation of the full-duplex end-to-end communication protocol described in pk(4). If fd is a file descriptor open for reading and writing, pkopen carries out the initial synchronization and returns an identifying pointer. The pointer is used as the first parameter to pkread, pkwrite, and pkclose. Pkread, pkwrite and pkclose behave analogously to read, write and close(2). However, a write of zero bytes is meaningful and will produce a corresponding read of zero bytes. SEE ALSO
pk(4), pkon(2) DIAGNOSTICS
Pkfail is called upon persistent breakdown of communication. Pkfail must be supplied by the user. Pkopen returns a null (0) pointer if packet protocol can not be established. Pkread returns -1 on end of file, 0 in correspondence with a 0-length write. BUGS
This simulation of pk(4) leaves something to be desired in needing special read and write routines, and in not being inheritable across calls of exec(2). Its prime use is on systems that lack pk. These functions use alarm(2); simultaneous use of alarm for other puposes may cause trouble. deprecated PKOPEN(3)
All times are GMT -4. The time now is 06:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy