0

Help with dynamic length of arrays being passed into a function

I'm trying to work through a few problems. This one involves combining two "list" by passing them to a function that can write them in alternating order. My first big question is why does the dynamic length only show the two arrays being passed to the function as having 2 items? In the main code the arrays are both 3 items long, yet in the function they are only 2. Also if I was wanting to combine this into a new array, how could I go about doing that? My thoughts are the function would still be a void function or would I have to allow it to return an int? I was thinking something like: int new_arr = com_arr(*arr1, *arr2); then writing a loop to print the new array. I know time complexity would be worse but trying to possible code this to take in user input and maybe even create a linked list at some point. Thanks for any input. https://code.sololearn.com/chSsU2TLbG19/?ref=app

26th Oct 2018, 5:11 PM
Ryan
Ryan - avatar
1 ответ
+ 1
Thanks for the info. I have read that some people like to build a struct, but I’m confused at how those are passed as arguments. struct Array arr1[] shouldnt work so is there a way to get a dynamic length. and if that was put in as struct arr1->length = sizeof(arr1)/sizeof(arr[0]); has is arr1.length able to be passed as an argument. (int* (arr1.length), ...) Sorry this is so long and all over the place and I know a lot of the code is most likely wrong but I just cant seem to hammer some of this stuff out. I think I have pointer, array of pointers, pointers to arrays, and array of arrays down a bit and then its like all the wires/rules get crossed lol.
27th Oct 2018, 11:46 PM
Ryan
Ryan - avatar