1
尝试从csv文件动态分配数据。我正在试图制作一个数组结构,其中包含2维数组。问题是当我尝试为结构中的数组分配内存时,我得到访问冲突。用评论标记问题区域。任何帮助表示赞赏。在结构中动态分配数组-c
typedef struct current{
char **data;
}*CurrentData;
CurrentData getData(FILE *current){
CurrentData *AllCurrentData = malloc(NUM_ITEMS * sizeof(CurrentData));
/*allocate struct data memory, skipping the first line of data*/
while ((ch = fgetc(current)) != EOF){
if (firstNewLine == 0){
firstNewLine++;
}
if (firstNewLine > 0){
if (ch == '\n'){
AllCurrentData[newLineCount]->data = malloc(COLUMNS * sizeof(char)); //problem here//
newLineCount++;
}
}
}
}
newLineCount在哪里初始化为0? – OldProgrammer
@OrProgrammer没有主要的,所以我认为他只是显示了“重要”的代码。 – Radnyx