您的位置:首页 > 其它

标准IO文件操作

2009-04-28 11:09 369 查看
标准I/O
1.#include<stdio.h> #include <wchar.h>
int fwide(FILE *fp, int mode);//设置流定向(宽定向返回正/字节定向返回负/未定向返回0)
mode参数值为负:试图使指定的流是字节定向的;正:宽定向;0不试图设置流的定向
2.void setbuf(FILE *restrict fp, char *restrict buf);
int setvbuf(FILE *restrict fp, char *restrict buf, int mode, size_t size);// 返回(0/-1)
//更改缓冲类型(流被打开后也应该在对该流未执行任何操作时调用)
mode 参数的选项:_IOFBF (全缓冲) _IOLBF (行缓冲)_IONBF(不带缓冲,将忽略buf和size)
3.int fflush(FILE *fp);//冲洗流,将流中的数据传给内核,然后清空缓冲区。返回(0/EOF)
4.FILE *fopen(const char *restrict pathname, const char *restrict type);//打开指定的文件
FILE *freopen(const char *restrict pathname, const char *restrict type, FILE* restrict fp)
//在一个指定的流上打开文件,若流已打开则先关闭流,若已定向则清除定向。
FILE *fdopen(int filedes, const char *type);
//获取一个现有的文件描述符,并使一个标准的I/O流与该描述符相结合。
//成功返回文件指针,出错返回NULL
5.int fclose(FILE *fp);//关闭一个打开的流,返回(0/EOF)
6.int getc(FILE *fp);
int fgetc(FILE *fp);
int getchar(void); //读取一个字符;成功返回下一个字符,若已到文件结尾或出错返回EOF
7.int ferror(FILE *fp);
int feof(FILE *fp);//测试文件是否出错和到达结尾;为真返回非0,否则返回0
void clearerr(FILE *fp);//清除错误和结束标志
8.int ungetc(int c, FILE *fp);//将字符压回流中;成功返回c,出错返回EOF
9.int putc(int c, FILE *fp);
int fputc(int c, FILE *fp);
int putchar(int c);//输出函数,成功返回c,出错返回EOF
10.char *fgets(char *restrict buf, int n, FILE *restrict fp);
char *gets(char *buf);//每次输入一行;成功返回buf,出错或文件结尾则返回NULL
11.int fputs(const char *restrict str, FILE *restrict fp);
int puts(const char *str);//输出一行的函数;成功返回非负值,出错则返回EOF
12.size_t fread(void *restrict ptr, size_t size,size_t nobj,FILE *restrict fp);
size_t fwrite(const void *restrict ptr, size_t size, size_t nobj, FILE *restrict fp);
//二进制I/O操作,返回读或写的对象数(即nobj)
13.long ftell(FILE *fp);//返回当前的文件位置指示;成功返回当前文件位置指示,失败-1L
int fseek(FILE *fp, long offset, int whence);//为打开的文件设置新的偏移量(0/非0)
void rewind(FILE *fp);//将一个流设置到文件的起始位置
14.off_t ftello(FILE *fp);//成功返回当前文件的位置指示(与上就差返回类型),失败返回-1
int fseeko(FILE *fp, off_t offset, int whence);//成功返回0,失败返回非0
15.int fgetpos(FILE *restrict fp, fpos_t *restrict pos);
//将文件位置指示器的当前值存入指向的对象中
int fsetpos(FILE *fp, const fpos_t *pos);//用pos的值将流重新定位到该位置;成功0失败非0;
16.int printf(const char *restrict format,...);
  int fprintf(FILE *restrict fp, const char *restrict format,…);//成功返回输出字符数/负值
int sprintf(char *restrict buf, const char *restrict format,…);
int snprintf(char *restrict buf, size_t n, const char *restrict format,…);
  //成功返回存入数组的字符数,出错则返回负值
17.scanf(const char *restrict format, …);
int fscanf(FILE *restrict fp, const char *restrict format,…);
int sscanf(const char *restrict buf, const char *restrict format, …);
  //返回指定的输入项数;若输入出错或在任意变换前已到达文件结尾则返回EOF
18.int fileno(FILE *fp);//获取文件描述符;返回该流相关联的文件描述符
19.char *tmpnam(char *ptr);//创建临时文件 //返回指向唯一路径的指针
FILE *tmpfile(void); //若成功则返回文件指针,若出错则返回NULL
20.char *tempnam(const char *directory, const char *prefix);//指定目录和前缀创建临时文件
21.int mkstemp(char *template)//指定临时文件的名字创建;成功返回文件描述符,出错返回-1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: