Thank you very much vincetg2 for the clear solution. It was quite usefull for me. I modified your code a little bit, perhaps this will be usefull for another one. I'm not a C expert,So if you have any sugegestions about the code, please post a reply. I think, this is the right way to create a 2D array by a function. It seems to work for me, but perhaps I overlooked something? Thanks again for the snippet, anyway.
Code:
char** create_2D_char_array( int numrows, int numcols){
char **data;
data = (char **) malloc(numrows * sizeof(char *));
if(data == NULL){
free(data);
printf("Memory allocation failed while allocating for dim[].\n");
exit(-1);
}
//
/* Allocate integer memory for the second dimension of a dim[][]; */
register int i;
for(i = 0; i < numrows; i++) {
data[i] = (char *) malloc(numcols * sizeof(char));
if(NULL == data[i]){
free(data[i]);
printf("Memory allocation failed while allocating for dim[x][].\n");
exit(-1);
}
}
return *&data; // Success
}