Declaring a C function to return an array
Posted
by Jaska
on Stack Overflow
See other posts from Stack Overflow
or by Jaska
Published on 2009-09-21T08:26:03Z
Indexed on
2010/03/21
10:41 UTC
Read the original article
Hit count: 270
Filed under:
c
How can I make a function which returns an array? I tried this
const int WIDTH=11;
const int HEIGHT=11;
int main() {
char A[WIDTH][HEIGHT];
A=rand_grid(WIDTH,HEIGHT);
return 0;
}
// Initializes a random board.
char[][] rand_grid(int i, int k) {
char* A[i][k];
for(j=0;j<i;++j) {
for(l=0;l<k;++l) {
A[j][l]=ran(10);
}
}
return A;
}
// Returns a random number from the set {0,...,9}.
int ran(int i) {
srand((unsigned int) time(0));
return(rand()%10);
}
© Stack Overflow or respective owner