The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM
Home Forums Register Rules & FAQ Members List Arcade Search Today's Posts Mark Forums Read


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.


Other UNIX.COM Threads You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to transpose data elements in awk ahjiefreak Shell Programming and Scripting 2 05-13-2008 01:44 AM
just want certail elements frenchface Shell Programming and Scripting 1 05-10-2008 06:38 PM
Reomve elements from a path name kgeasler Shell Programming and Scripting 3 03-26-2008 10:48 AM
Read elements of a xml file?????? ahmedwaseem2000 Shell Programming and Scripting 6 01-23-2008 11:50 PM
How to list mirrored elements? (pv, vg, lv) cactux AIX 4 11-29-2006 06:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-14-2008
Read Only
 

Join Date: Jun 2006
Posts: 105
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiReddit! Stumble this Post!Spurl this Post!
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 10:22 AM. Reason: added code tags
Reply With Quote
Google UNIX.COM
Forum Sponsor
Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 07:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger

Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102