The C Programming Language 学习笔记
来源:互联网 发布:雨人手机软件 编辑:程序博客网 时间:2024/06/06 10:29
- 单引号的字符表示一个整数,该值等于此字符在机器字符集中对应的数值,我们称之为字符常量。但是他只不过是小的整型数的一种写法而已。例如,'A'是一个字符常量,在ASC字符集中其值是65(即‘A’的内部表示值是65),当然,用‘A’比65好,因为‘A’的意义更明确。
- 习题1-8
Exercise 1-8 Write a program to count blanks, tabs, and newlines. #include <stdio.h>int main(void){ int blanks, tabs, newlines; int c; int done = 0; int lastchar = 0; blanks = 0; tabs = 0; newlines = 0; while(done == 0) { c = getchar(); if(c == ' ') ++blanks; if(c == '\t') ++tabs; if(c == '\n') ++newlines; if(c == EOF) { if(lastchar != '\n') { ++newlines; /* this is a bit of a semantic stretch, but it copes * with implementations where a text file might not * end with a newline. Thanks to Jim Stad for pointing * this out. */ } done = 1; } lastchar = c; } printf("Blanks: %d\nTabs: %d\nLines: %d\n", blanks, tabs, newlines); return 0;}
其中的lastchar != '\n'让我很困惑,注释的意思是如果文件不是以一个newline结束的,那么这行也应该加入到newlines中。但我在ubuntu下的终端下,如果不起新的行,无法通过ctrl + D(windows使用ctrl + z)输入EOF,也就不存在不以‘\n’结束的情况了。但是如果以管道的方式读进去,最后一行就可以是不以‘\n’结束的点击打开链接。为此研究了‘\n’, 具体研究结果参照这里 - c语言传递参数时采用值传递,要想修改实参,需要传指针。当把数组名用作参数时,传递的数组首元素的位置或地址,并不复制数组本身,在被调用函数中,可以通过数组下标访问或者修改数组元素的值。
- 《The C Programming Language》学习笔记
- The C Programming Language 学习笔记
- 《The C programming language》学习笔记
- The C Programming Language 笔记
- 《The C Programming Language》笔记
- 《The C Programming Language》学习笔记——位运算
- The C programming language 学习笔记(一)
- The C Programming Language 笔记(2)
- The C Programming Language 笔记(3)
- The C programming language 笔记_1
- 《The C programming language》笔记2
- 《The C Programming Language》阅读笔记1
- The Swift Programming Language学习笔记
- The C programming language
- the c programming language
- The C Programming Language
- 《The C Programming Language》学习笔记——指针与数组1
- 翻译《the c programming language》
- 国富国穷
- 重新组织数据之十三 :Replace Type Code with Class(以类取代型别码)
- ecmall get_users_count() fatal error
- SIP学习笔记
- 重新组织数据之十四 :Replace Type Code with Subclasses(以子类取代型别码)
- The C Programming Language 学习笔记
- DWR使用总结
- ASP.Net 文件上传大小限制解决方案修改IIS7/7.5配置
- android AIDL服务
- SIP协议简介
- php文件下载原理
- jQuery 入门教程(42): jQuery UI Tab 示例(二)
- Linux系统启动过程介绍
- 重新组织数据之十五 :Replace Type Code with State/Strategy(以State/strategy 取代型别码)