Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Creating n amount of arrays in C?

Name: Anonymous 2013-03-07 21:18

A simple question, i hope there's a simple answer.

The program I'm making will take in data, and based on an integer, I'd like to make a number of arrays based on that integer.

Any help? Thanks.

Name: Anonymous 2013-03-07 21:33

#define ARRAY_LENGTH 20

int **array_of_arrays(int n) {
int i;
int **array_of_arrays = malloc(sizeof(int *) * n);
for(i = 0; i < n; i++) {
array_of_arrays[i] = malloc(sizeof(int) * ARRAY_LENGTH);
}
return array_of_arrays;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List