I needed an array to hold 4 values defined within a function fn1, so I created an array: int somearray[4]; in main() . Although I understand that values might be entered into an array individually by number: somearray[1]=3;, my numbers are in variables n1, n2, n3, n4.
Is there a method to accomplish this?
I have considered the possibility of creating an array within the function, then transferring individual values into somearray[].
I'm evidently quite new to C, and the thought of returning the array also came to mind. I'm quite sure it's not right, but it would help to have some confirmation anyway.
Thanks in advance.
To Makoto:
main(){
int sumarray[4];
int n1,n2,n3,n4;
int fn1(){
n1=1;
n2=23;
n3=29;
n4=14;
sumarray[]={n1,n2,n3,n4}
return 0;
}
return 0;
}
well.. at least that's what I was attempting to do anyway