ファイルや標準入力から1行づつ文字列を読み込む関数
int get_next_line(int fd, char **line);
- ファイルディスクリプタ
int fd
- 読み込んだ文字列を入れる用のポインタ
char **line
- 1 -> まだ行が残っている
- -1 -> 最後の行を読み込んだ
使用する.cファイルの上部にインクルードしてください。
#include get_next_line.h
-
char *get_line; int r; int fd; fd = open('file_path', O_RDONLY); r = 1; while (r == 1) { r = get_next_line(fd, &get_line); if (r == -1) break; /* 好きな処理 */ free(get_line); } close(fd);