Reading a file line by line in C

前端 未结 4 860
长情又很酷
长情又很酷 2020-12-12 01:34

I am trying to write some code that will open a file, read its content line by line and store each of these lines into an array.

First I open the file and count the

4条回答
  •  旧巷少年郎
    2020-12-12 02:04

    You haven't created an array of strings, you've created a pointer to an array of strings. you need to malloc your array in part2 to be count of lines * number of char's per line. then move your read lines into each subsequent position of array.

    [edit]
    one more thing.....
    your strings are X length. 'C' strings aren't X length, they're X+1 length :)
    [/edit]

提交回复
热议问题