Hi, I was wondering how I could get a variable out of a function.
For example, in the function scanf, if you do
The variable var has the value of whatever you put in, and can be used.
Here are a few snippets of my code:
Code:
int getValue (int *arr, int numElements, int pos, int value) {
int c, o;
if (pos > numElements) {
c = 2;
} else if (arr[pos] < 0) {
c = 1;
} else {
c = 0;
value = arr[pos]; // I need this able to be used outside of getValue
}
return (c);
}
// This is how I would need it to be used.
if (getValue(arr, mpos, n, o) == 0) {
printf("array[%d] is %d\n", n, o);
exit(0);
}
I'm not really sure what to do. I tried doing value* = arr[pos]; but I get the error "error: invalid type argument of ‘unary *’". Please help (:
UPDATE: Fixed.