博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
fgetc的用法(一个字符的显示文件中的数据)
阅读量:6975 次
发布时间:2019-06-27

本文共 605 字,大约阅读时间需要 2 分钟。

 
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
unistd.h
>
int
main(
int
argc,
char
*
argv[])
{
FILE
*
fp;
char
ch;
fp
=
fopen(
"
test
"
,
"
r
"
);
//
fopen产生一个文件指针
while
((ch
=
fgetc(fp))
!=
EOF)
//
以文件流方式读取文件,以EOF结尾
{
sleep(
1
);
putc(ch,stdout);
fflush(stdout);
//
刷新缓冲区,让输出显示
}
fclose(fp);
return
0
;
}

程序2:

 
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
unistd.h
>
#include
<
fcntl.h
>
int
main(
int
argc,
char
*
argv[])
{
char
ch[
10
];
int
fd;
fd
=
open(
"
./test
"
,O_RDONLY);
while
(read(fd,ch,
1
)
!=
0
)
{
sleep(
1
);
write(
1
,ch,
1
);
//
fflush(stdout);
}
close(fd);
return
0
;
}

转载地址:http://klesl.baihongyu.com/

你可能感兴趣的文章
无限级别菜单下拉
查看>>
Linux oprofile命令
查看>>
HashMap 实现原理(复习)
查看>>
Leetcode: LFU Cache && Summary of various Sets: HashSet, TreeSet, LinkedHashSet
查看>>
JAVA数据结构--队列
查看>>
[zz]配置RHEL6使用CentOS6的yum源
查看>>
linux debug : addr2line追踪出错地址
查看>>
oracle 好书( 09 对象管理 )
查看>>
网站是否有播放音乐功能
查看>>
架构设计:远程调用服务架构设计及zookeeper技术详解(上篇)
查看>>
web开发中的 emmet 效率提升工具
查看>>
41、java与mysql乱码的问题
查看>>
细说 Form (表单)
查看>>
在Web应用和IntelliJ IDEA中使用Spring框架
查看>>
用缓动函数模拟物理动画
查看>>
MongoDB索引相关文章-摘自网络
查看>>
RBAC权限设计图 [转]
查看>>
2017Windows下安装pip
查看>>
用JAVA发送一个XML格式的HTTP请求
查看>>
GraphicsStatsService之2 UI绘制的时间信息来源
查看>>