Array Problem.
-
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.
-
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.
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.
-
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.
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 bechar*
. 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
-
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 bechar*
. 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
Thank you Richard for giving me the Idea. Thank You Very Much.
-
Thank you Richard for giving me the Idea. Thank You Very Much.
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
-
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.