Programming abstractions in C阅读笔记:p139-p143
《Programming Abstractions In C》学习第55天,p139-p140,总结如下:
一、技术总结
1.文件I/O操作
文件I/O操作可以分为一下这些步骤:
(1)声明文件指针对象。
File *infile;
(2)打开文件
fopen()。打开文件的模式有“r”, "w", "a"三种模式。
(3)传输数据
读取文件的方式可以是character by character( getc()/putc() ),也可以是line by line( fget()/fput() )。
(4)关闭文件
fclose()。
2.文件I/O操作示例:复制文件
#include <stdio.h>
#include <stdbool.h> // for bool, true, false data type
#include <stdlib.h> // for exit()
void CopyRemovingComments(FILE *infile, FILE *outfile);
int main() {
// 声明文件指针对象
FILE *infile, *outfile;
char *infileName, *outfileName;
/*
* 打开文件:fopen()
* 如果文件不存在,则返回NULL,所以需要检查
*/
infileName = "D:\\CProject\\chater3.4\\jabber.txt"; // 这里使用的是绝对路径,也可以使用相对路径
outfileName = "D:\\CProject\\chater3.4\\jabbercopy.txt";
infile = fopen(infileName, "r");
if (infile == NULL) {
printf("Cannot open input file: %s \n", infileName);
exit(0);
}
/*
* 传输数据
* 传输数据有很多种方式,例如chracter by character(getc/putc),line by line(fget/fput, ReadLine)
* 为了解决stdio.h存在的一些问题,作者对stdio进行了封装,封装后得到的的是simpio
*/
outfile = fopen(outfileName, "w");
if (outfile == NULL) {
printf("Cannot open output file: %s \n", outfileName);
exit(0);
}
CopyRemovingComments(infile, outfile);
/*
* 关闭文件
*/
fclose(infile);
fclose(outfile);
printf("Copying is completed");
return 0;
}
void CopyRemovingComments(FILE *infile, FILE *outfile) {
int ch, nch;
bool commentFlag; // 这里使用的是stdbool.h接口中的bool
commentFlag = false; // 这里使用的是stdbool.h接口中的false,书中使用的是封装后的FALSE
while ((ch = getc(infile)) != EOF) {
if (commentFlag) {
if (ch == '*') {
nch = getc(infile); //
if (nch == '/') {
commentFlag = false;
} else {
ungetc(nch, infile);
}
}
} else {
if (ch == '/') {
nch = getc(infile);
if (nch == '*') {
commentFlag = true;
} else {
ungetc(nch, infile);
}
}
if (!commentFlag) {
putc(ch, outfile);
}
}
}
}
二、英语总结
1.endpoint什么意思?
答:c.the end of sth(终点)。
2.transfer什么意思?
答:transfer也是一个在计算机相关资料中经常看到的词。p140, For an input file, the function read data from the file into your program; for an output file, the function transfer data from the program to the file。数据从文件到程序中,或者从程序中到文件,即是一种transfer。通过该例句,对tranfer有一个形象的了解。
3.intermix什么意思?
答:
(1)解释:vi/vt. to combine two or more different things。
(2)搭配:intermix sth with sth。
(3)例句:p140, Doing so allows you to intermix numeric data with strings and other data types。
三、参考资料
1. 编程
(1)Eric S.Roberts,《Programming Abstractions in C》:https://book.douban.com/subject/2003414
2. 英语
(1)Etymology Dictionary:https://www.etymonline.com
(2) Cambridage Dictionary:https://dictionary.cambridge.org
欢迎搜索及关注:编程人(a_codists)
Programming abstractions in C阅读笔记:p139-p143的更多相关文章
- Mongodb Manual阅读笔记:CH3 数据模型(Data Models)
3数据模型(Data Models) Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mon ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画 学习目标 熟悉蒙皮动画的术语: 学习网格层级变换 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试 代码工程地址: https://github.co ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化 学习目标 对Direct 3D编程在 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...
- Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数
原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...
- 阅读笔记 1 火球 UML大战需求分析
伴随着七天国庆的结束,紧张的学习生活也开始了,首先声明,阅读笔记随着我不断地阅读进度会慢慢更新,而不是一次性的写完,所以会重复的编辑.对于我选的这本 <火球 UML大战需求分析>,首先 ...
- [阅读笔记]Software optimization resources
http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++ 7. The efficiency of differe ...
- 《uml大战需求分析》阅读笔记05
<uml大战需求分析>阅读笔记05 这次我主要阅读了这本书的第九十章,通过看这章的知识了解了不少的知识开发某系统的重要前提是:这个系统有谁在用?这些人通过这个系统能做什么事? 一般搞清楚这 ...
随机推荐
- odoo部署安全性问题
本文档描述在生产中或在面向Internet的服务器上设置Odoo的基本步骤.它是在安装之后进行的,对于没有在internet上公开的开发系统来说,它通常不是必需的.警告如果您正在设置公共服务器,请务必 ...
- LINIUX 查询命令的 区别 chich whereis locate fing
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. locate 配合数据库查看文件位置 ...
- NLM 公布了一个新的重新设计的 PubMed 数据库
经常使用 PubMed 的童鞋可能已经发现,美国国家医学图书馆(NLM)在今年 10 月份左右发布了一个新的重新设计的版本以取代 PubMed 数据库的现有版本,新版本现在已经上线,可以通过下面的链接 ...
- c++中vector容器的用法
C语言中const关键字是constant的缩写,通常翻译为常量.常数等,它可以修饰变量.数组.指针.函数参数. vector 是向量类型,它可以容纳许多类型的数据,如若干个整数,所以称其为容器.ve ...
- 一分钟学一个 Linux 命令 - cat 和 tail
前言 大家好,我是 god23bin.今天我给大家带来的是 Linux 命令系列,每天只需一分钟,记住一个 Linux 命令不成问题.今天,需要你花费两分钟时间,因为我们要介绍的是两个常用的查看文件内 ...
- 【LeetCode专题#基本计算器】基本计算器I,图解中序表达式转逆波兰表达式,太难了
基本计算器 https://leetcode.cn/problems/basic-calculator/?envType=list&envId=cKNEfNsF 给你一个字符串表达式 s ,请 ...
- 【HarmonyOS】详解低代码端云一体化开发之数据模型
[关键字] 元服务.低代码平台.端云一体化开发.数据模型.拖拽式UI [1.写在前面] 上一篇中分享了关于低代码平台开发元服务的基本使用,有兴趣的可以看一下,文章地址如下: https://devel ...
- k8s kong部署
docker部署postgres docker run -d \ --name kong-postgres \ -e POSTGRES_PASSWORD=kong \ -e PGDATA=/var/l ...
- 如何构建您的第一部AWS机器学习服务
目录 <如何构建您的第一部 AWS 机器学习服务> 背景介绍 随着深度学习的广泛应用于机器学习领域的各个方面,AWS 成为了一种重要的深度学习平台.作为 AWS 机器学习服务的第一部,如何 ...
- Paimon读取流程
查询模式 先来看看官网关于Paimon查询模式的说明 可以看到查询模式围绕snapshot展开, 而snapshot分了两种一种是Last compact snapshot和 last snapsho ...