Originally Posted by
wirefree101
Greetings.
I seek assistance understanding the procedure for passing (receiving) arrays to (from) functions. The following code is indicative of my misunderstanding:
Code:
#include <stdio.h>
char retArr(char []); //this is global, all functions can work with it, no passing needed.
int main(){
//char tempArr[5]; not needed
int i;
char rcvArr[5];
/*tempArr (the name of the array, is actually pointing to the base of the array with
it's name. No return type is needed for an array that you send to a function.
*/
retArr[rcvArr); //is all you need tempArr is not needed at all
// rcvArr = retArr(tempArr);
//let's make it a full-blown peep show, instead: :)
for(i = 0; i < 5; i++)
printf("rcvArr[%d]: %c\n", i, rcvArr[i]);
// printf("rcvArr[0]: %c\n", rcvArr[0]);
return 1;
}
void retArr(char arr[]){ //arr is now another name for rcvArr[] - same array though
arr[0] = 'A';
arr[1] = 'B';
arr[2] = 'C';
arr[3] = 'D';
arr[4] = 'E';
//no return needed
}
Hope that helps.