《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的更多相关文章

  1. Mongodb Manual阅读笔记:CH3 数据模型(Data Models)

    3数据模型(Data Models) Mongodb Manual阅读笔记:CH2 Mongodb CRUD 操作Mongodb Manual阅读笔记:CH3 数据模型(Data Models)Mon ...

  2. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十三章:角色动画 学习目标 熟悉蒙皮动画的术语: 学习网格层级变换 ...

  3. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十一章:模板测试 代码工程地址: https://github.co ...

  4. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第六章:在Direct3D中绘制 代码工程地址: https://gi ...

  5. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第四章:Direct 3D初始化 学习目标 对Direct 3D编程在 ...

  6. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二章:矩阵代数 学习目标: 理解矩阵和与它相关的运算: 理解矩阵的乘 ...

  7. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...

  8. 阅读笔记 1 火球 UML大战需求分析

    伴随着七天国庆的结束,紧张的学习生活也开始了,首先声明,阅读笔记随着我不断地阅读进度会慢慢更新,而不是一次性的写完,所以会重复的编辑.对于我选的这本   <火球 UML大战需求分析>,首先 ...

  9. [阅读笔记]Software optimization resources

    http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++   7. The efficiency of differe ...

  10. 《uml大战需求分析》阅读笔记05

    <uml大战需求分析>阅读笔记05 这次我主要阅读了这本书的第九十章,通过看这章的知识了解了不少的知识开发某系统的重要前提是:这个系统有谁在用?这些人通过这个系统能做什么事? 一般搞清楚这 ...

随机推荐

  1. React-hooks 父组件通过ref获取子组件数据和方法

    我们知道,对于子组件或者节点,如果是class类,存在实例,可以通过 React.createRef() 挂载到节点或者组件上,然后通过 this 获取到该节点或组件. class RefTest e ...

  2. Javascript 常见的循环方式总结

    本文地址: https://www.cnblogs.com/zichliang/p/17412968.html 在Javascript中有很多种循环方式.有多种循环方式可以用来遍历数组.对象.以及执行 ...

  3. npm run serve/build 背后的真实操作

    vue CLI 用起来的确很舒服,方便省事,但他经过层层封装很难明白,执行完那个npm run serve/build 后他都干了些什么,甚至不知道整个项目是怎么跑起来的,今天自己抽时间就去瞅瞅,为加 ...

  4. web自动化05-鼠标操作

    鼠标操作方法   1.常见的鼠标操作   点击.右击.双击.悬停.拖拽等   2.selenium中的封装鼠标操作   说明:在Selenium中将操作鼠标的方法封装在ActionChains类中   ...

  5. 如何使用C++ 在Word文档中创建列表

    列表分类是指在Word文档中使用不同格式排序的列表,来帮助我们一目了然地表达出一段文字的主要内容.比如,当我们描述了某个主题的若干点,就可以用列表把它们一一表达出来,而不是写成完整的段落形式.同时,列 ...

  6. Unity框架与.NET, Mono框架的关系

    什么是C# C#是一种面向对象的编程语言. 什么是.NET .NET是一个开发框架,它遵循并采用CIL(Common Intermediate Language)和CLR(Common Languag ...

  7. Python 列表、字典、元组的一些小技巧

    1. 字典排序 我们知道 Python 的内置 dictionary 数据类型是无序的,通过 key 来获取对应的 value.可是有时我们需要对 dictionary 中的 item 进行排序输出, ...

  8. CKS 考试题整理 (13)-使用 sysdig 检查容器里里的异常进程

    Task 使用运行时检测工具来检测 Pod tomcat 单个容器中频发生成和执行的异常进程 有两种工具可供使用: sysdig falco 注: 这些工具只预装在cluster的工作节点,不在 ma ...

  9. Go语言学习总结

    1. 跳出/执行下一次循环. {标签名}: for true { ... for true { ... break/continue {标签名} //默认不加标签,则跳出最近一层循环.加了标签可以跳出 ...

  10. 免杀系列之去除Defender令牌权限

    本文展示了Windows存在的一个小bug,该问题允许攻击者绕过保护反恶意软件(AV/EDR)免受各种形式攻击的Windows安全机制(Windows Protected Process Light) ...