《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. Vue全局公共服务类mixin

    首先,简单介绍下mixin: Mixin是面向对象程序设计语言中的类,提供了方法的实现.其他类可以访问mixin类的方法而不必成为其子类 Mixin类通常作为功能模块使用,在需要该功能时"混 ...

  2. el-table自适应列宽

    这里可对内容为文本的列进行自适应列宽 以下为 工具方法 /** * 使用span标签包裹内容,然后计算span的宽度 width: px * @param valArr */ function get ...

  3. 2013年蓝桥杯C/C++大学A组省赛真题(排它平方数)

    题目描述: 小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是 ...

  4. ODOO之四Odoo 13 开发之模块继承

    Odoo 的一个强大功能是无需直接修改底层对象就可以添加功能.这是通过其继承机制来实现的,采取在已有对象之上修改层来完成.这种修改可以在不同层上进行-模型层.视图层和业务逻辑层.我们创建新的模块来做出 ...

  5. 手动删除了Linux下syslog--/var/log/messages怎么办?

    引言 Linux小白很容易犯得一个错误就是:查看日志的时候,尤其是系统日志,由于日志太多,把系统日志手动删除了.也就是把/var/log/messages文件删除了,而不是删除文件的内容.直接删除文件 ...

  6. CMU15445 (Fall 2020) 数据库系统 Project#3 - Query Execution 详解

    前言 经过前两个实验的铺垫,终于到了执行 SQL 语句的时候了.这篇博客将会介绍 SQL 执行计划实验的实现过程,下面进入正题. 总体架构 一条 SQL 语句的处理流程可以归纳为: SQL 被 Par ...

  7. #PowerBi Superchange PowerBi 序言部分笔记(2)

    Xmind本文思维导图 序言部分,主要讲述了BI的分类及发展,以及作者推荐的学习方法.重点是介绍了powerbi的主要四大步骤. 即: 一:数据采集 Data acquisition: Power B ...

  8. GetX 关于报错 Null check operator used on a null value的解决

    import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'logic.dart'; class Ge ...

  9. 【SpringBoot】整合Redis

    1.前言 最近公司在做项目,用到了redis,,发现自己一点都不会,然后就乘闲暇时间,自己学习一些redis相关的知识,在这里分享给像我一样的初学者. 2.我的项目结构: 2.1 pom.xml &l ...

  10. 即构发布 LCEP 低代码互动平台产品 RoomKit,实现互动房间0代码搭建

    2月5日,全球云通讯服务商ZEGO即构科技发布低代码互动平台 LCEP(Low-code Engagement Platform)产品 RoomKit,支持1V1在线课堂.小班课.大班课.视频会议.视 ...