linux c之用fopen、fputs、fgets、 fseek来对文件进行写、替换、读

135 阅读1分钟

1、函数说明

1、fgets

 

#include
        char *fgets(char *s, int size, FILE *stream);

 


功能:从文件流读取一行,送到缓冲区,使用时注意以下几点:
返回值:成功时s指向哪返回的指针就指向哪,出错或者读到文件末尾时返回NULL

 

 

 

 

 

 

2、fputs

 

#include

int fputs(const char *s, FILE *stream);
        int puts(const char *s);

 

 

 


返回值:成功返回一个非负整数,出错返回EOF

fputs向指定的文件写入一个字符串,puts向标准输出写入一个字符串。

3、fseek

 

头文件:#include <stdio.h>

定义函数:int fseek(FILE * stream, long offset, int whence);

 


函数说明:
fseek()用来移动文件流的读写位置.

1、参数stream 为已打开的文件指针,
2、参数offset 为根据参数whenc