how to read a string from a \n delimited file

后端 未结 5 505
天涯浪人
天涯浪人 2021-01-18 10:20

I\'m trying to read a return delimited file. full of phrases.

I\'m trying to put each phrase into a string.

The problem is that when I try to read the file w

5条回答
  •  一生所求
    2021-01-18 11:18

    fscanf(file,"%50[^\n]\n",string);
    
    1. Every character except \n will be consumed by [^\n]

    2. Maximum 0f 50 chars will be consumed (make sure string has space for 51 atleast)

    3. ..\n",string this makes sure that \n is also consumed so that the next call does not just return a null string.

提交回复
热议问题