分类: LINUX
2009-02-20 07:35:10
(1)#include
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 fds, const char *type);
若成功则返回文件指针,若出错则返回NULL
Type:r、w、a、r+、w+、a+
int fclose(FILE *fp);
若成功则返回0,若出错则返回NULL
(2) #include
int getc(FILE *fp); 每次一个字符的I/O
int fgetc(FILE *fp);
int getchar(void);
若成功则返回下一个字符,若已达到文件结尾或出错则返回EOF
int ferror(FILE *fp);
int feof(FILE *fp);
void clearerr(FILE *fp);
若条件为真则返回非0值,否则返回0
int putc(int c, FILE *fp);
int fputc(int c, FILE *fp);
int putchar(int c);
若成功则返回c,若出错则返回EOF
char *fgets(char *restrict buf, int n, FILE *restrict fp); 每次一行I/O
char *gets(char *buf);
若成功则返回buf,若已达到文件结尾或出错则返回EOF
int *fputs(const char *restrict str, FILE *restrict fp);
int *puts(const char *str);
若成功则返回非负值,若出错则返回EOF
size_t fread(void *restrict buf, size_t size, size_t nobj, FILE *restrict fp);
size_t fwrite(const *restrict buf, size_t size, size_t nobj, FILE *restrict fp);
读或写的对象数
(3) #include
long ftell(FILE *fp);
off_t ftell(FILE *fp);
若成功则返回当前文件位置指示,若出错则返回
int fseek(FILE *fp, long offset, int whence);
int fseek(FILE *fp, off_t offset, int whence);
若成功则返回0,若出错则返回非0值
void rewind(FILE *fp);
int fgetpos(FILE *restrict fp, fops_t *restrict pos);
int fsetpos(FILE *fp, const fops_t *pos);
若成功则返回0,若出错则返回非0值
(4) #include
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, …);
若成功则返回存入数组的字符数,若出错则返回负值
int scanf(const char *restrict format, …);
int fscanf(FILE *restrict fp, const char *restrict format, …);
int sscanf(char *restrict buf, const char *restrict format, …);
指定的输入项数,若输入出错或在任意变换前已到达文件结尾则返回EOF
(5)#include
int fileno(FILE *fp);