《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. python通过变量名称的反射,获取变量的引用

    有一些极端情况下,例如变量名称是动态的,我们无法直接调用变量名,如何获取到变量的引用呢? aa = [globals()["xxxx"]]

  2. [NISACTF 2022]bingdundun~

    [NISACTF 2022]bingdundun~ 考点 文件上传.Phar://伪协议 一.题目 打开题目,发现是一道文件上传的题目,因为提示了可以压缩包,所以尝试直接上传zip文件,然后利用PHP ...

  3. 2013年蓝桥杯C/C++大学A组省赛真题(高斯的日记)

    题目描述: 大数学家高斯有个好习惯:无论如何都要记日记. 他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210 后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第 ...

  4. odoo开发教程十二:web controlle

    一:路由 odoo.http.route(route=None, **kw) 装饰器可以将对应方法装饰为处理对应的http请求,该方法须是Controller的子类. route -- 字符串或数组, ...

  5. Doris(七) -- 修改表、动态和临时分区、join的优化

    修改表 修改表名 -- 1.将名为 table1 的表修改为 table2 ALTER TABLE table1 RENAME table2; -- 示例 ALTER TABLE aggregate_ ...

  6. 读文献先读图——主成分分析 PCA 图

    上周五彩斑斓的气泡图 有让你眼花缭乱吗? 本周,化繁为简的PCA图 你值得拥有!  数据分析| 科研制图﹒PCA 图 关键词:主成分分析.降维 1665 年的鼠疫 牛顿停课在家提出了万有引力 ;183 ...

  7. 【python基础】循环语句-break关键字

    1.break关键字 break关键字,其作用是在循环中的代码块遇到此关键字,立刻跳出整个循环,执行循环外的下一条语句. 其在while和for循环中的作用示意图如下: 1.1break在while循 ...

  8. 从JDK源码级深入剖析main方法的运行机制

    如果你是一名Java应用开发工程师,你应该对"public static void main(String[] args)"这段代码再熟悉不过了,然而你是否了解main方法是如何调 ...

  9. 3. AOP

    1. 代理模式 1.1 概念 ① 介绍 二十三种设计模式中的一种,属于结构型模式.它的作用就是通过提供一个代理类,让我们在调用目标方法的时候,不再是直接对目标方法进行调用,而是通过代理类间接调用.让不 ...

  10. 5 大数据实战-hive实战分析

    1 内部表 Show databses; Use hive_data; 1.1 创建内部表 CREATE TABLE SOGOUQ2(DT STRING,WEBSESSION STRING,WORD ...