#include <stdio.h>
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 fd,const char *type);
--All three return: file pointer if OK,NULLon error
#include<stdio.h>
int
main()
{
/*redirect standard output to file test.out*/
if(freopen("./test.out","w",stdout)==NULL)
fprintf(stderr,"errorredirectingstdout\n");
/*this output will go to a file test.out*/
printf("Hello World\n");
/*close the standard output stream*/
fclose(stdout);
return 0;
}
#include<stdio.h>
int
main()
{
FILE *fp = fdopen(0,"w+");
fprintf(fp,"%s\n", "Hello world!");
fp =fdopen(1,"w+");
fprintf(fp,"%s\n","Hello world!");
fclose(fp);
}
#include <stdio.h>
int getc(FILE *fp);
int fgetc(FILE *fp);
int getchar(void);
All three return: next character if OK,EOFon end of file or error
#define getc(_fp) _IO_getc (_fp)
#include <stdio.h>
int ferror(FILE *fp);
int feof(FILE *fp);
Both return: nonzero(true) if condition is true, 0 (false) otherwise
void clearerr(FILE *fp);
#include <stdio.h>
int ungetc(intc,FILE *fp);
Returns:cif OK,EOFon error
#include <stdio.h>
int putc(intc,FILE *fp);
int fputc(intc,FILE *fp);
int putchar(intc);
All three return:cif OK,EOFon error
#include <stdio.h>
char *fgets(char *restrict buf,int n,FILE *restrict fp);
char *gets(char *buf);
Both return:buf if OK,NULL on end of file or error
#include<stdio.h>
#define BUFFSIZE 4096
int
main()
{
char buf[BUFFSIZE];
fgets(buf,5,stdin);
puts(buf);
fgets(buf,10,stdin);
puts(buf);
return 0;
}
~
#include <stdio.h>
int fputs(const char *restrict str,FILE *restrict fp);
int puts(const char *str);
Both return: non-negative value if OK,EOFon error
原文地址:http://blog.csdn.net/windeal3203/article/details/38820417