2021年3月29日
摘要: https://www.cnblogs.com/LoyenWang/ https://www.cnblogs.com/linhaostudy/[]() https://elixir.bootlin.com/linux[]() https://my.oschina.net/u/3857782 http 阅读全文
posted @ 2021-03-29 14:23 将军之盾 阅读(50) 评论(0) 推荐(0) 编辑
  2011年7月12日
摘要: 源自《The C Programming Language》P102 pr5-11: 修改程序entab和detab(第一章练习中编写的函数),使它们接受一组作为参数的制表符停止位。如果启动程序时不带参数, 则使用默认的制表符停止位设置。 代码: #include <stdio.h>#include <stdlib.h>#define TABINC 8int main(int argc, char* argv[]){ int c; int pos; int nb; int tab_inc; pos = 1; nb = 0; if(argc == 1) tab_inc = 阅读全文
posted @ 2011-07-12 17:12 将军之盾 阅读(457) 评论(0) 推荐(0) 编辑
  2011年7月10日
摘要: 源于《The C Programming Language》P14的一道例题: 统计输入中的行数,单词数,字符数(单词的定义:其中不包括空格,制表符,换行符的字符序列) #include <stdio.h> #define IN 1 #define OUT0 int main() { int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while((c = getchar()) != EOF) ++nc; if(c == '/n') ++nl; if(c == ' ' || c == &# 阅读全文
posted @ 2011-07-10 15:41 将军之盾 阅读(416) 评论(0) 推荐(0) 编辑
摘要: 源于《The C Programming Language》P17 pr1-13: 编写一个程序,打印输入中单词长度的直方图。 代码 main.c 1 /************************************************************** 2 直方图定义: 3 n:某个长度单词出现的次数(长度为4的单词出现了9次,则n = 9) 4 M:出现最频繁的长度的次数 5 H:定义的直方图的最大长度(本例中为MAXHIST) 6 **************************************************************/ 7 . 阅读全文
posted @ 2011-07-10 15:40 将军之盾 阅读(1146) 评论(0) 推荐(0) 编辑
摘要: 来源于《The C Programming Language》的一道习题(P13,PR1-9): 编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替 自己实现: #include <stdio.h> int main() { int c, flag; flag = 0; while((c = getchar()) != EOF) if(c == ' ' && flag == 0) { putchar(c); ++flag; } else if(c == ' ' && flag != 0) ++flag 阅读全文
posted @ 2011-07-10 15:37 将军之盾 阅读(230) 评论(0) 推荐(0) 编辑
  2011年6月22日
摘要: 源自《The C Programming Language》P83 pr5-2: 模仿函数getInt 的实现方法,编写一个读取浮点数的函数getFloat,getFloat函数的返回值应该是什么类型呢? 代码:View Code 1 #include <stdio.h> 2 #include <ctype.h> 3 4 int getInt(int *); 5 int getFloat(double *); 6 7 #define SIZE 100 8 #define MAX_FLT 2147483648 //double 8字节,但2^63太大,此处用2^31作为阈 阅读全文
posted @ 2011-06-22 19:40 将军之盾 阅读(365) 评论(0) 推荐(0) 编辑
  2011年6月16日
摘要: 源自《The C Programming Language》P75 pr4-12, 4-13: 编写递归版本的itoa及reverse函数 代码:View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 void printd(int n); 5 void itoa(int n, char s[]); 6 void reverse(char s[]); 7 8 //int end; 9 //int beg; 10 11 #define MAXLINE 100 12 13 int main() 14 { 15 int 阅读全文
posted @ 2011-06-16 01:33 将军之盾 阅读(613) 评论(0) 推荐(0) 编辑
  2011年6月8日
摘要: 源自《The C Programming Language》 P62 ex4.3: 计算例如:(1 - 2) * (4 + 5)的值,采用逆波兰表示法(即后缀表示法) 代码: main.cView Code 1 #include <stdio.h> 2 #include <stdlib.h> //为了使用库函数atof 3 #include <math.h> //使用sin, exp, pow等数学函数 4 #include <string.h> //使用strcmp, strlen等字符串函数 5 #include "getop.h& 阅读全文
posted @ 2011-06-08 01:29 将军之盾 阅读(1533) 评论(5) 推荐(0) 编辑
  2011年6月1日
摘要: 源自《The C Programming Language》P62 pr4-2,代码位于ex4.2中:对atof函数进行扩充,使它能够处理形如:123.45e-6的科学表示法,其中浮点数后面可能会紧跟一个e或E以及一个指数 代码:main.c 1 #include <stdio.h> 2 #include <ctype.h> 3 4 #define MAXLINE 100 5 6 int getLine(char s[], int lim); 7 double atof(char s[]); 8 int pow(int base, int expn); 9 10 int 阅读全文
posted @ 2011-06-01 19:43 将军之盾 阅读(1429) 评论(0) 推荐(0) 编辑
  2011年5月25日
摘要: 源自《The C Programming Language》 P53 pr3-4,代码位于ex3.6中: 在数的对二的补码表示中,我们编写的itoa函数不能处理最大的负数,即n等于-(2^(字长-1))的情况。请解释原因, 修改函数使得它在任意机器上运行时都能得到正确结果。 代码:main.c 1 #include <stdio.h> 2 #include <string.h> 3 4 #define MAXLINE 100 5 6 void itoa(int n, char s[],int width); 7 void itob(int n, char s[], in 阅读全文
posted @ 2011-05-25 23:52 将军之盾 阅读(403) 评论(0) 推荐(0) 编辑