【PTA】6-2 读文章(*) (31 分)
2024-10-19 20:56:14
请编写函数,从文件中读出文章,将其输出到屏幕上。
函数原型
void ReadArticle(FILE *f);
说明:参数 f 为文件指针。函数读出 f 所指示文件中的文章,将其输出到屏幕上。
裁判程序
#include <stdio.h>
#include <stdlib.h>
void ReadArticle(FILE *f);
int main()
{
FILE *f;
f = fopen("Article.txt", "r");
if (!f)
{
puts("文件无法打开!");
exit(1);
}
ReadArticle(f);
if (fclose(f))
{
puts("文件无法关闭!");
exit(1);
}
return 0;
}
/* 你提交的代码将被嵌在这里 */
答案:
void ReadArticle(FILE *f)
{
int ch;
while(!feof(f))
{
ch = getc(f);
if(ch == EOF)
break;
else
putc(ch,stdout);
}
}
最新文章
- lustre文件系统部署流程
- flush vs ob_flush
- ahjesus SSHkey登陆linux服务器,无需密码,ubuntu
- 钉子和小球_DP
- C语言的字符测试函数
- Unity 使用实体类
- Eclipse中Ctrl+Alt+Down和Ctrl+Alt+Up不起作用
- Python之while循环
- BFC和清除浮动
- Back-off pulling image \";registry.access.redhat.com/rhel7/pod-infrastructure:latest
- SQL查看死锁+清理死锁
- 数组 this.setData快捷赋值
- flask run方法和run_simple
- JDK1.6新特性,WebService强化
- [笔记] FreeBSD使用小技巧
- 数据库引擎InnoDB和MyISAM区别
- .net中session的使用
- tbnet编译
- MySQL协议分析(2)
- hadoop2.2.0编译、安装和测试
热门文章
- Python 字典是如何解决哈希冲突的
- [BUUCTF]REVERSE——[ACTF新生赛2020]rome
- LuoguP7375 [COCI2018-2019#5] Jarvis 题解
- Android NDK开发篇:Java与原生代码通信(异常处理)
- java源码——对文件内容的查找和替换(开始写界面咯)
- 【LeetCode】1023. Camelcase Matching 解题报告(Python)
- 【LeetCode】980. Unique Paths III解题报告(C++)
- 【LeetCode】831. Masking Personal Information 解题报告(Python)
- LeetCode118. Pascal&#39;s Triangle 杨辉三角
- CAS学习笔记一:CAS 授权服务器简易搭建