当前位置:网站首页>C Primer Plus---程序清单13.2 reduto.c
C Primer Plus---程序清单13.2 reduto.c
2022-04-22 13:48:00 【邓某人的父亲】
程序清单13.2 reduto.c
/* come from <C Primer Plus> * 程序清单13.2 reduto.c * 把文件压缩为原来的1/3 * 注意: main参数可以在IDE的Parameters栏中设置,每个参数对应一个字符串,多个参数之间用空格分开. */
#include <stdio.h>
#include <stdlib.h> // for exit()
#include <string.h> // for strcpy(), strcat()
#define LEN 40
int main(int argc, char *argv[])
{
FILE *in, *out;
int ch;
char name[LEN];
int count = 0;
// 检查命令行参数
if (argc < 2)
{
fprintf(stderr, "Usage: %s filename\n", argv[0]);
exit(1);
}
// set up input
if ((in = fopen(argv[1], "r")) == NULL)
{
fprintf(stderr, "I couldn't open the file \"%s\"\n", argv[1]);
exit(2);
}
// set up output
strcpy(name, argv[1]); // copy filename
strcat(name, ".red"); // append .red
if ((out = fopen(name, "w")) == NULL)
{
// open file for writing
fprintf(stderr, "Can't create output file.\n");
exit(3);
}
// copy data
while ((ch = getc(in)) != EOF)
if (count++ % 3 == 0)
putc(ch, out); // print every 3rd char
// clean up
if (fclose(in) != 0 || fclose(out) != 0)
fprintf(stderr, "Error in closing files\n");
return 0;
}
版权声明
本文为[邓某人的父亲]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_62121252/article/details/124342921
边栏推荐
- 单阶段和两阶段目标检测
- QT explorer and Use of QRC file
- 华为云媒体査勇:华为云在视频AI转码领域的技术实践
- 那些年我们一起优化的SQL
- Word length and data type
- 【直播来袭】OneOS系统教程全面上线,邀您和ST、OneOS一起来学习啦!
- Special topic of game partners: breederdao reaches a new height in cooperation with fancy birds
- What are the types of blocking queues in the thread pool?
- 在珠江期货办理开户安全吗?
- C# 7.0 使用下划线忽略使用的变量
猜你喜欢

好物合集(1)

eBPF学习 - 入门

2022年 MathorCup 思路分享

七年谋“一剑”,站在边缘云的风口,如何加速企业数字化转型?

Detailed explanation of heap sorting (C language)

What is the lifecycle of automated testing?

Sixtool multi-functional multi-in-one generation hanging assistant system source code

Fizz企业级微服务网关-服务编排,祭出终结BFF层的大杀器

华为云媒体査勇:华为云在视频AI转码领域的技术实践

指定Swagger接口文档中参数序列化组件为Newtonsoft.Json
随机推荐
Xen thermal repair technology (basic understanding)
What is the lifecycle of automated testing?
Electromagnetic furnace heating reflow welding
Is Guoyuan futures account opening reliable? Is the money safe?
LeetCode-819 最常见的单词
osgEarth配置地图资源
Redis (VI) - set of common data types of redis
一篇文章快速搞懂 Apache SkyWalking 的 OAL
[software test series x] stress test scheme
好物合集(1)
eBPF学习 - 入门
那些年我们一起优化的SQL
no main manifest attribute / . There is no main manifest attribute in jar
Harbor v2.5更新,都增加了哪些功能?
Fizz企业级微服务网关-服务编排,祭出终结BFF层的大杀器
国元期货开户是否可靠?资金安全吗?
从月薪10k到30k的必走之路:自动化测试
Is the account opening of Guoyuan futures company reliable? Is the transaction safe?
快速串讲——JVM内存的区域划分
《深入 C 语言和程序运行原理》11 标准库:深入理解标准 IO(学习笔记)