Link to home
Start Free TrialLog in
Avatar of justinY
justinY

asked on

reference file or reference value

Hi experts,
my input file is like this:

A         B
1         2
AA      BB

my refernece file is like this:

A      B       C
1      2       3
AA    BB     CC

I want to return
C
3
CC
on my output file

I am going to do
A-B
1-2
AA-BB

and

A-B C
1-2 3
AA-BB CC
in my reference file and my input file and compare them, if match then return value

So, I have the followings
typedef struct
{
       char keydata[100];
       char valuedata[100];
}keyref;

char* findkeyvalue( keyref* ref, const char* k)
{
         for(int i=0;i <MaxSize;i++)
         {
              if (!strcmp(ref[i].keydata, k))
                     return ref[i].valuedata;
         }
          return "NONE"
};

main()
{
     ifstream fin( myinputfile);
     ifstream fin1( myreferencefile);
     keyfer refer_data[MaxSize];
     string refer_read;
     int k=0;
     getline(fin1, refer_read)
     while( getline (fin1, refer_read))
     {
          vector<string> refer_row_elem;
          Getfields(refer_read1, refer1_row_elem, ',');
          refer_row_elem[0] += "-";
          refer_row_elem[0] += refer_row_elem[1];
          strcpy(refe_data[k].keydata, refer_row_elem[0].c_str());
          strcpy(refe_data[k].valuedata, refer_row_elem[2].c_str());
          k++;
       }

       while( getline (fin, row_read))
     {
          vector<string> row_elem;
          Getfields(row_read, row_elem, ',');
          row_elem[0] += "-";
          row_elem[0] += row_elem[1];
       }

       char * valuefound;
       valuefound = findkeyvalue(refer_data, row_elem[0].c_str());  
}
It returns NONE, no match found, Whats wrong ?
If I compare just 2 columns, no +=, then  I have match.
But after +=, then no match found.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of rstaveley
rstaveley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Second comment should read:

// Load the map using the key file and generate the output file
I'll try that again... Second comment should read:

/* Read through key file and generate the output file doing look-ups on the map (assumes all keys have values in the reference file missing values will show as blank lines) */