文件:feof的用法

当文件没读到尾巴之前,feof(fd)=0  ;

当文件读到尾巴 ,feof(fd) =  !0   ;

#include<stdio.h>
#include<string.h>
int main()
{
        FILE *fd;
        char *writebuff = "huangcaichenghenshuaiqwertyuioasdfghjklzxcvbnnnnnnm123456789";
        char readbuff[128] = {0};
        fd = fopen("./text2","w+");
        printf("writebuff=%s\n",writebuff);
        int n_fwrite = fwrite(writebuff,sizeof(char),strlen(writebuff),fd);

        int size = fseek(fd,0,SEEK_SET);
        //feof(fd)=0  before fd to zero; feof(fd)=nonzero when fd to zero 
        while(!feof(fd)){
        int n_fread = fread(readbuff,sizeof(char),4,fd);
        printf("read:%d bytes;context:%s\n",n_fread,readbuff);
        }
        fclose(fd);
        return 0;

}
hcc@ubuntu:~/LinuxSystemProgramming/FILE$ ./a.out
writebuff=huangcaichenghenshuaiqwertyuioasdfghjklzxcvbnnnnnnm123456789
read:4 bytes;context:huan
read:4 bytes;context:gcai
read:4 bytes;context:chen
read:4 bytes;context:ghen
read:4 bytes;context:shua
read:4 bytes;context:iqwe
read:4 bytes;context:rtyu
read:4 bytes;context:ioas
read:4 bytes;context:dfgh
read:4 bytes;context:jklz
read:4 bytes;context:xcvb
read:4 bytes;context:nnnn
read:4 bytes;context:nnm1
read:4 bytes;context:2345
read:4 bytes;context:6789
read:0 bytes;context:6789

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值