标准库IO总结

--------IO----------
<stdlib-IO>
    FILE *fopen(char *file,char *mode);
    int fclose(FILE *fp);
in:
    input format conversion:
    1.read input from stdin:
    int scanf(char *format,...);
    2.read input from the stream pointer stream:
    int fscanf(FILE *stream,char *format,...);
    3.read input from the char poiter ptr:
    int sscanf(char *str,char *format,...);
    4.input of charactor from stdin
    int getchar(void);
    5.input of charactor from stream pointer stream:
    int fgetc/getc(FILE *stream);
    6.input of string from stream(can be stdin) and stores them into buffer poionted by s:
    char *fgets(char *s,int size,FILE *stream);
    7.binary(阻塞型) stream input
    size_t fread(void *ptr,size_t size,size_t nmemb,FILE *stream)
out:
    1.write in stdout:
    int printf(char *format,...);
    int putchar(int c);
    int puts(char *s);
    2.write in file:
    int fprintf(FILE *stream,char *format,...);
    int fputc(int c,FILE *stream);
    int fputs(char *s,FILE *stream)
    3.write in string:
    int sprintf(char *ptr,char *format,...);
    4.binary stream output:
    size_t fwrite(void *ptr,size_t size,size_t nmemb,FILE *stream);

offset:

    1.set file position indicator:
    set to the beginning:
    void rewind(FILE *stream);
    set to a position by adding offset bytes to the position specified by whence:
    int fseek(FILE *stream,long offset,int whence);
    set a position by adding pos to the begining:
    int fsetpos(FILE *stream,fpos_t *pos);
    2.get file position
    get posion to return,the top len is 2^32:
    int ftell(FILE *stream);
    get posion and store it into pos:
    int fgetpos(FILE *stream,fpos_t *pos);
dynamic memory:
    void * malloc(size_t size);
    void free(void *ptr);

[标准输入输出的的缓冲区]
1.这个缓冲区既不是内核中的缓冲区,也不是用户分配的缓冲区,而是由编译器维护的进程空间中的缓冲区;
2.输出信息先存入缓冲区,当遇到刷新条件时才会输出。
3.标准中没有规定各种流是什么缓冲,stdout是哪种缓冲区由环境决定。例如,在终端中stdout为行缓冲,

刷新条件如下:
行缓冲:换行、满、强制刷新fflush(FILE *stream)   终端设备的stdout是行输出
全缓冲:满、强制刷新   默认为全缓冲,除了终端设备
无缓冲:立即输出



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值