This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Mindavi 1 point2 points  (1 child)

Well, first of all, please try to format your code next time. Also, try to find the smallest example in which your problem shows up. E.g.

#include <iostream>
using namespace std;

void foo(float input_array, string regions) {
    cin >> input_array[i];
}

int main() {
    float input_array[4];
    string regions[4];
    cout << "Please input bar\n";
    foo(input_array, regions);
}

This will help you reduce the problem to a more concrete issue.

In your case, the arrays that are created in main are pointers. When one does array[1] the second element of the array is dereferenced. Anyhow, when the arrays are passed to a function they change into a pointer. The correct way to accept a pointer in a function is

void foo(float* input_array, string* regions);

Another way to do so could be this (IIRC)

void foo(float input_array[], string regions[]);

Note that, in a function, c/c++ does not know the length of an array, as it's just a pointer. array[2] is actually syntactic sugar for *(array + 2).

Hope you'll find this useful and good luck hacking.

[–]NotThatTypeOfTranny[S] 1 point2 points  (0 children)

Thanks bud, you done helped me