Ocelote Posted September 23, 2015 Share Posted September 23, 2015 Hi everyone! I'm currently struggling with this: Is there a way of passing an array as an argument, fill it with integers and then return that array to be used by another function? Something like this? int pt_numbers_array[]; int create_points(vector v1; int array[]; int total_pts) { vector new_pos1 = v1; for (int i = 0; i < total_pts; i++){ int pt1 = addpoint(geoself(), new_pos1); array = pt1; new_pos1 += {0,1,0}; } return array[]; } create_points(@P,pt_numbers_array[],5); Actually, this is not my only question. So, is it posible to get some personal VEX training with someone? I don't wan't to abuse the forum... Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 23, 2015 Share Posted September 23, 2015 (edited) You don't need to return it from your function. It's passed by reference so it will be modified. Run this in Detail mode: #define PRINT(val, text) printf("numbers %s: %d\n", text, val) vector CENTER = set(0, 1, 0); int numbers[]; void AddPoints(const vector pos; const int maxcount; int refarray[]) { vector newPos = pos; for (int i = 0; i < maxcount; i++) { int currentNumber = addpoint(geoself(), newPos); refarray[i] = currentNumber; newPos += {0, 1, 0}; } } PRINT(numbers, "before"); AddPoints(CENTER, 3, numbers); PRINT(numbers, "after"); Edited September 24, 2015 by fântastîque Mântragorîè 1 Quote Link to comment Share on other sites More sharing options...
Ocelote Posted September 23, 2015 Author Share Posted September 23, 2015 Yeah man, that was it! Thank you very much for your attention and support. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.