如何为静态数组的内容分配指针数组?

时间:2023-02-11 21:18:13
char myData[505][3][50];   //2D array, each 50 chars long   
char **tableData[505] = {NULL};  

const char* text;
text = sqlite3_column_text(stmt, col_index);

strcpy(myData[row_index][c_index],text); 

tableData[row_index] = myData[row_index][c_index]; <--?  

I would like to assign the pointer to pointer array tableData to the content of the static array myData but do not know the syntax, or if it possible. Any advice?

我想将指针数组tableData的指针分配给静态数组myData的内容,但不知道语法,或者是否可能。有什么建议?

2 个解决方案

#1


Just

tableData[row_index] = myData[row_index]

#2


What tableData is going to represent?

tableData将代表什么?

If it's going to represent an array of strings (I'll call a char* a string for simplicity in this answer), you should edit the declaration to char* tableData[len];.

如果它将表示一个字符串数组(为了简单起见,我将在这个答案中调用一个char *字符串),你应该将声明编辑为char * tableData [len];。

If it's going to represent a 2D array of strings (which is what the current declaration means), you should set it as tableData[i] = myData[x].

如果它将表示字符串的2D数组(这是当前声明的含义),则应将其设置为tableData [i] = myData [x]。

myData[x][y] is a single string, not an array of strings. In the last line of your snippet, you are trying to assign it to something that expects an array of strings. This is not a valid operation.

myData [x] [y]是单个字符串,而不是字符串数组。在您的代码段的最后一行,您尝试将其分配给需要字符串数组的内容。这不是有效的操作。

#1


Just

tableData[row_index] = myData[row_index]

#2


What tableData is going to represent?

tableData将代表什么?

If it's going to represent an array of strings (I'll call a char* a string for simplicity in this answer), you should edit the declaration to char* tableData[len];.

如果它将表示一个字符串数组(为了简单起见,我将在这个答案中调用一个char *字符串),你应该将声明编辑为char * tableData [len];。

If it's going to represent a 2D array of strings (which is what the current declaration means), you should set it as tableData[i] = myData[x].

如果它将表示字符串的2D数组(这是当前声明的含义),则应将其设置为tableData [i] = myData [x]。

myData[x][y] is a single string, not an array of strings. In the last line of your snippet, you are trying to assign it to something that expects an array of strings. This is not a valid operation.

myData [x] [y]是单个字符串,而不是字符串数组。在您的代码段的最后一行,您尝试将其分配给需要字符串数组的内容。这不是有效的操作。