Hi All
I have written a map program. The program is simple
I have the input file input.dat which has the following
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
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