Reading from a file and storing in array

后端 未结 4 605
刺人心
刺人心 2020-12-09 01:00

I\'ve written the following program to read line by line from a file and store it in the words array. The output should be two random words from the array. But surprisingly

4条回答
  •  执念已碎
    2020-12-09 01:25

    You repeatedly overwrite the memory in line_buffer. The words array contains only pointers this variable.

    You should either use a multi-dimensional array or allocate memory at runtime.

    Btw: Bad things will happen when you pass more than 20 lines to your code ...

提交回复
热议问题