Initialize 2-D array of unknown size

前端 未结 6 1949
我在风中等你
我在风中等你 2021-01-16 00:42

I have a 2-D array of characters e.g. char aList[numStrings][maxLength]. ideally, during program execution I want to be able to modify the contents of aList i.

6条回答
  •  不知归路
    2021-01-16 01:40

    If your plan is to populate while reading in the file you could do one of two things.

    Either store the number of strings as the first element in the file, then the suggestion by jgottula would work well.

    Or, must you use an array? You could read them directly into a linked list, and then when finished reading, move them into an array, and free up the linked list.

提交回复
热议问题