fgets() 函數從開啟的檔案中傳回一行。
fgets() 函數會在到達指定長度( length - 1 )、碰到換行符號、讀到檔案結尾(EOF)時(以先到者為準),停止傳回一個新行。
如果失敗該函數傳回FALSE。
fgets(file,length)
參數 | 描述 |
---|---|
file | 必需。規定要讀取的文件。 |
length | 可選。規定要讀取的位元組數。預設是1024 位元組。 |
上面的程式碼將輸出:
Hello, this is a test file.
上面的程式碼將輸出:
Hello, this is a test file.There are three lines here.This is the last line.