Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Array Problem.

Array Problem.

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasedata-structurestutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janaswamy uday
    wrote on last edited by
    #1

    Hi all I am having two Arrays with different Length. I have some elements in both Array's In Ascending Order. Also Note that this Elements are always in Ascending Order. Example ------- char array1[200]; char array2[100]; Now both arrays have some elements array1[0]= "1"; array1[1]= "1.1"; array1[2]= "2"; array1[3]= "2.1"; array2[0]= "1"; array2[1]= "1.1"; array2[2]= "1.2"; array2[3]= "2"; array2[4]= "3"; array2[5]= "3.1"; array2[6]= "3.2"; Now i have to Arrange this Two Arrays such that. Array1 Elements should be ------------------------- array1[0]= "1"; array1[1]= "1.1"; array1[2]= ""; //Empty as element array2 contain element array1[3]= "2" array1[4]= "2.1" array1[5]= "" //Empty as element array2 contain element array1[6]= "" array1[7]= "" Array2 Elements should be ------------------------- array2[0]= "1" array2[1]= "1.1" array2[2]= "1.2" array2[3]= "2" array2[4]= "" //Empty as element array1 contain element array2[5]= "3" array2[6]= "3.1" array2[7]= "3.2" ------------------------- How can i replace a Blank if any one Array Element have no Element at that Index. Help me out. Thanks, Uday.

    _ L A 3 Replies Last reply
    0
    • J janaswamy uday

      Hi all I am having two Arrays with different Length. I have some elements in both Array's In Ascending Order. Also Note that this Elements are always in Ascending Order. Example ------- char array1[200]; char array2[100]; Now both arrays have some elements array1[0]= "1"; array1[1]= "1.1"; array1[2]= "2"; array1[3]= "2.1"; array2[0]= "1"; array2[1]= "1.1"; array2[2]= "1.2"; array2[3]= "2"; array2[4]= "3"; array2[5]= "3.1"; array2[6]= "3.2"; Now i have to Arrange this Two Arrays such that. Array1 Elements should be ------------------------- array1[0]= "1"; array1[1]= "1.1"; array1[2]= ""; //Empty as element array2 contain element array1[3]= "2" array1[4]= "2.1" array1[5]= "" //Empty as element array2 contain element array1[6]= "" array1[7]= "" Array2 Elements should be ------------------------- array2[0]= "1" array2[1]= "1.1" array2[2]= "1.2" array2[3]= "2" array2[4]= "" //Empty as element array1 contain element array2[5]= "3" array2[6]= "3.1" array2[7]= "3.2" ------------------------- How can i replace a Blank if any one Array Element have no Element at that Index. Help me out. Thanks, Uday.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      From the source and destination arrays you provided and your explanation, I do not understand what you're trying to do. Could you rephrase your question or maybe another example would help.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • J janaswamy uday

        Hi all I am having two Arrays with different Length. I have some elements in both Array's In Ascending Order. Also Note that this Elements are always in Ascending Order. Example ------- char array1[200]; char array2[100]; Now both arrays have some elements array1[0]= "1"; array1[1]= "1.1"; array1[2]= "2"; array1[3]= "2.1"; array2[0]= "1"; array2[1]= "1.1"; array2[2]= "1.2"; array2[3]= "2"; array2[4]= "3"; array2[5]= "3.1"; array2[6]= "3.2"; Now i have to Arrange this Two Arrays such that. Array1 Elements should be ------------------------- array1[0]= "1"; array1[1]= "1.1"; array1[2]= ""; //Empty as element array2 contain element array1[3]= "2" array1[4]= "2.1" array1[5]= "" //Empty as element array2 contain element array1[6]= "" array1[7]= "" Array2 Elements should be ------------------------- array2[0]= "1" array2[1]= "1.1" array2[2]= "1.2" array2[3]= "2" array2[4]= "" //Empty as element array1 contain element array2[5]= "3" array2[6]= "3.1" array2[7]= "3.2" ------------------------- How can i replace a Blank if any one Array Element have no Element at that Index. Help me out. Thanks, Uday.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The first thing you need to fix is your definitions of the arrays. You have defined both arrays as char and are then saying that each element holds a pointer to a string so your definition needs to be char*. To get the results you want, you first need to sort both arrays in order. Next create a third array (array3) containing all the elements of each array, but only 1 copy of duplicate elements (i.e. a merge of array1 and array2). Now iterate the elements of array3 and put empty strings in any elements which do not exist in array1. Repeat this process for array2 and you should end up with array3 and array4 containing what you want. There is most likely a simpler way to do this but I can't think of one off the top of my head.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        J 1 Reply Last reply
        0
        • L Lost User

          The first thing you need to fix is your definitions of the arrays. You have defined both arrays as char and are then saying that each element holds a pointer to a string so your definition needs to be char*. To get the results you want, you first need to sort both arrays in order. Next create a third array (array3) containing all the elements of each array, but only 1 copy of duplicate elements (i.e. a merge of array1 and array2). Now iterate the elements of array3 and put empty strings in any elements which do not exist in array1. Repeat this process for array2 and you should end up with array3 and array4 containing what you want. There is most likely a simpler way to do this but I can't think of one off the top of my head.

          Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

          J Offline
          J Offline
          janaswamy uday
          wrote on last edited by
          #4

          Thank you Richard for giving me the Idea. Thank You Very Much.

          L 1 Reply Last reply
          0
          • J janaswamy uday

            Thank you Richard for giving me the Idea. Thank You Very Much.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Happy to help; don't forget to mark answer as accepted.

            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

            1 Reply Last reply
            0
            • J janaswamy uday

              Hi all I am having two Arrays with different Length. I have some elements in both Array's In Ascending Order. Also Note that this Elements are always in Ascending Order. Example ------- char array1[200]; char array2[100]; Now both arrays have some elements array1[0]= "1"; array1[1]= "1.1"; array1[2]= "2"; array1[3]= "2.1"; array2[0]= "1"; array2[1]= "1.1"; array2[2]= "1.2"; array2[3]= "2"; array2[4]= "3"; array2[5]= "3.1"; array2[6]= "3.2"; Now i have to Arrange this Two Arrays such that. Array1 Elements should be ------------------------- array1[0]= "1"; array1[1]= "1.1"; array1[2]= ""; //Empty as element array2 contain element array1[3]= "2" array1[4]= "2.1" array1[5]= "" //Empty as element array2 contain element array1[6]= "" array1[7]= "" Array2 Elements should be ------------------------- array2[0]= "1" array2[1]= "1.1" array2[2]= "1.2" array2[3]= "2" array2[4]= "" //Empty as element array1 contain element array2[5]= "3" array2[6]= "3.1" array2[7]= "3.2" ------------------------- How can i replace a Blank if any one Array Element have no Element at that Index. Help me out. Thanks, Uday.

              A Offline
              A Offline
              Addy Tas
              wrote on last edited by
              #6

              Hi, If you'd you std::vector you could just insert a item where needed. Use a for loop on array two, where an item does not exits in array one, add it. My two cents, AT

              Cogito ergo sum

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups