Thread: Isolate same records from one array to another.

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    26

    Exclamation Isolate same records from one array to another.

    Hello All,

    By trade I'm an Oracle JD Edwards Developer, one of the toolsets available to me is an Oracle centric version of C++.

    My task is to write from Array A to Array B the multiple occurrences of the same records. Below i will give a data representation of what my task is....

    Thanks in advance....

    Array A: --------- Array B:
    aaa ---------------- ccc
    bbb ---------------- ccc
    ccc ---------------- ccc
    ccc ---------------- ddd
    ccc ---------------- ddd
    ddd --------------- fff
    ddd --------------- fff
    eee
    fff
    fff
    ggg
    Last edited by FrankCLT; 09-30-2018 at 02:00 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest inserting the values into a std::map<std::string, std::size_t> or an equivalent std::unordered_map if order doesn't actually matter. This way, you map the values to the count of their frequencies, upon which you just need to iterate over the map once to extract those values for which the count is greater than 1.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    Thank you for your input....In your explanation you mention std::map<std::string, std::size_t> unfortunately, I haven't seen this syntax in the C++ toolset\samples I have in the Oracle JD Edwards development environment.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Does the Oracle JD Edwards development environment support the C++ standard library? If it does, then this should be available.

    If not, then you can always code your own by implementing a balanced binary tree or hash table.

    Alternatively, you could sort the data then do a single pass to extract values that occur more than once. This could be easily done with std::sort, but again if your environment doesn't support the standard library you could always implement a sorting algorithm yourself.
    Last edited by laserlight; 09-30-2018 at 04:54 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Sep 2018
    Posts
    26

    Angry

    Just did a search of ALL .c files and nothing found as outlined in your example. I'm having difficulty in looping through Array A and selecting the multiple occurrences. I have tried many iterations using "for" loops, just can't seem to get the algorithm right.


    Thank again,
    FrankCLT

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Do you realize that files with a .c extension are usually C source files, not C++ source files. And don't forget that many parts of the STL (Standard Template Library) are header only implementations and that many C++ standard headers have no extension.

    I have tried many iterations using "for" loops, just can't seem to get the algorithm right.
    You're going to need to show some code illustrating what you've tried.

  7. #7
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    Below is the code and debug....the data is also represented, the red highlighted row should NOT be in aBoxTrkD[j].szBoxNumberStringD. Hope this helps. When looking at the Debug, there shouldn't be spaces between entries....It is doing some of the work but not all....Apologies for the influx of updates.....

    aBoxTrkA
    0 085085000303985330 1Z8R9A510346043690
    1 085085000303985330 1Z8R9A510347631301
    2 085085000303985330 1Z8R9A510347814159
    3 085085000303985330 1Z8R9A510347957540
    4 085085000303985507 1Z8R9A510346913571
    5 085085000303985507 1Z8R9A510347894671
    6 085085000303985521 1Z8R9A510346303480
    7 085085000303985521 1Z8R9A510347934163
    8 085085000303985620 1Z8R9A510346043690
    9 085085000303985637 1Z8R9A510346408331
    10 085085000303985637 1Z8R9A510348212726
    11 085085000303985729 1Z8R9A510347053436
    12 085085000303985729 1Z8R9A510347622311


    aBoxTrkD
    0 085085000303985330 1Z8R9A510346043690
    1 085085000303985330 1Z8R9A510347631301
    2 085085000303985330 1Z8R9A510347814159
    3 085085000303985330 1Z8R9A510347957540
    4 085085000303985507 1Z8R9A510346913571
    5 085085000303985507 1Z8R9A510347894671
    6 085085000303985521 1Z8R9A510346303480
    7 085085000303985521 1Z8R9A510347934163
    8 085085000303985637 1Z8R9A510346408331
    9 085085000303985637 1Z8R9A510348212726
    10 085085000303985729 1Z8R9A510347053436
    11 085085000303985729 1Z8R9A510347622311


    Isolate same records from one array to another.-code-jpgIsolate same records from one array to another.-debugstep-jpg
    Last edited by FrankCLT; 10-01-2018 at 08:47 AM.

  8. #8
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    So, when done aBoxTrkD should look like aBoxTrkA minus this entry....8 085085000303985620 1Z8R9A510346043690.

  9. #9
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So what exactly is being output?

    Also you should post your code as text inside code tags, not as a hard to read picture. Also it would be helpful to see how you're defining and initializing the input array.

    Have you followed the logic with your debugger, especially right before and right after the "problem entry"?

    You also need to realize that most people will not be able to compile your program because of the use of those non-standard functions, so you're going to need to do the hard work of debugging.

    By the way have you tried to find a forum dedicated to the JDE software? Does your company, by chance, have a "help" contract?

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Please post your code between [code][/code] tags.

    Fuzzy pictures of just tiny parts of your code are not that useful.

    TBH, there's no C++ in your example. It's just JDE wrapper functions around standard library functions like strcpy().


    Create a new C++ project with a single source file containing the following.
    Code:
    #include <iostream>
    #include <string>
    #include <map>
    int main ( ) {
    }
    Let's find out whether you actually have a C++ compiler with access to the standard library.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    The debug actually shows what is being populated in aBoxTrkD after the "for" loops are complete.

    aBoxTrkA is being populated from one of our shipper tables.

    We do have a support contract with JD Edwards, but they will only support their products, not custom stuff.....

    I guess i will just need to work through the sequencing of logic......

    I was incorrect, it is just C.....

    Thanks anyway.....
    FrankCLT

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Perhaps you would benefit from writing a couple of utility functions (which you can test independently) to help with readability.

    Code:
    if ( ! productInList(aBoxTrkD,numEntriesInTrkD,aBoxTrkA[i]) ) {
        addToProductList(aBoxTrkD,numEntriesInTrkD,aBoxTrkA[i]);
        numEntriesInTrkD++;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Okay, so this is actually C, not C++. Let's leave this in C++ programming forum for now though, but in the future concerning this environment you should post in the C forum.

    Now, is the data already sorted? Your sample input gives me the impression that that is so. Therefore, you don't need nested for loops: as I mentioned in post #4, a single pass will do:
    Code:
    j = 0
    duplicate = false
    duplicate_index = 0
    for i = 1 to i = N
        if input[i] == input[duplicate_index]
            if not duplicate
                duplicate = true
                result[j++] = input[duplicate_index]
            result[j++] = input[i]
        else
            duplicate = false
            duplicate_index = i
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    I will most definitly give this a go......

    Cheers....and Thank you,
    FrankCLT

  15. #15
    Registered User
    Join Date
    Sep 2018
    Posts
    26
    laserlight.....here is your sample rewritten...

    Code:
               j = 0;
               duplicate_index = 0;
               bDuplicate = FALSE;
               for (i = 1; i < vMax; i++)  
               {
                   if (jdestrcmpwithnull(aBoxTrkA[i].szBoxNumberStringA, aBoxTrkA[duplicate_index].szBoxNumberStringA)==0)
                   {
                       if  (!bDuplicate)  
                       {
                           bDuplicate = TRUE;
                           jdeStrncpy(aBoxTrkD[j++].szBoxNumberStringD, aBoxTrkA[i].szBoxNumberStringA, DIM(aBoxTrkD[i].szBoxNumberStringD));
                           jdeStrncpy(aBoxTrkD[j++].szBoxNumberStringD, aBoxTrkA[duplicate_index].szBoxNumberStringA, DIM(aBoxTrkD[i].szBoxNumberStringD));
                       }
                   }
                   else
                   {
                       bDuplicate = FALSE;
                       duplicate_index = i;
                   }
               }
    This works great....Thank you.......

    I have one glitch that I'm working through, in the aBoxTrkA, any that have more than 2 entries, (see sample) only populate twice in aBoxTrkD. Other than than it works well.....again thank you...

    FrankCLT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of Records
    By leocfox in forum C Programming
    Replies: 5
    Last Post: 04-29-2012, 10:13 PM
  2. array of records -> function
    By keisx in forum C Programming
    Replies: 3
    Last Post: 10-27-2009, 10:51 AM
  3. Array of records?
    By pobri19 in forum C Programming
    Replies: 6
    Last Post: 05-03-2008, 06:34 AM
  4. dynamic array of records
    By dustyrain84 in forum C Programming
    Replies: 2
    Last Post: 01-22-2004, 08:55 AM
  5. Replies: 4
    Last Post: 10-31-2002, 04:11 AM

Tags for this Thread