Read string from file in C

后端 未结 3 541
春和景丽
春和景丽 2020-12-19 19:21

I have a file with multiple strings, each string on a separate line. All strings are 32 character long (so 33 with the \'\\n\' at the end).

I am trying to read all t

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 19:58

    It goes something like this:

    char str[33]; //Remember the NULL terminator
    while(!feof(fp)) {
      fgets(str, 33, fp);
      printf("%s\n",str);
    }
    

提交回复
热议问题