1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
void func_str(string ***M, int &rows, int &cols ) {
// rows and cols will be known here
rows = 2;
cols = 5;
// set memory allocation
*M = (string**)malloc(5*sizeof(string*));
(*M)[0] = (string*) malloc(5*sizeof(string));
(*M)[1] = (string*) malloc(5*sizeof(string));
// trying to assign values to M[0][0], M[0][1]...
static string A[5] = {"aaa1","bbb1","ccc1","ddd1","eee1"};
memcpy((*M)[0], A, 5*sizeof(string));
A[0] = "aaa2";
A[1] = "bbb2";
A[2] = "ccc2";
A[3] = "ddd2";
A[4] = "eee2";
memcpy((*M)[1], A, 5*sizeof(string));
}
main () {
string **M;
int rows, cols;
func_str(&M, rows, cols);
return 0;
}
|