![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
TCPL
歌涛舞雨
随便
展开
-
TCPL 1-23(扩展版)
题目:编写一个删除C语言程序中所有的注释语句。要正确处理带引号的字符串与字符常量。在C语言中程序中,注释不允许嵌套。 #include <stdio.h> #include <stdlib.h> int main() { int c = 0; int pos = 1; int d = 0; while((c = getchar()) ...原创 2019-01-10 14:52:54 · 161 阅读 · 0 评论 -
字符串排序
该程序可以对输入的字符串进行排序,windows中以Ctrl+z结束。程序的思路是利用指针数组,指向存储在alloc函数分配的空间中的字符串,使用Qsort函数进行比较。在Qsort函数中,将key也就是待回归的值变为指针变量来存储指针数组中的地址,然后利用这个地址和其它指针数组中的地址传进strcmp函数中,来逐字比较字符串的大小,最后进行指针指向地址的交换。readline函数主要起一个读入输...原创 2019-03-25 15:55:41 · 206 阅读 · 1 评论 -
TCPL 4-13
题目:编写一个递归版本的reverse(s)函数,以将字符串s倒置; 这个题目真的让我困惑了很长时间,原因是我在测试时直接写了int *pstr = "hello",然而这样是将pstr指向了一个常量,它存储在静态存储区内,所以在下面想要修改时,就会出现错误。必须时用scanf或者strcpy函数来将值写入或复制到该变量内。 #include <stdio.h> #include...原创 2019-03-24 21:23:47 · 153 阅读 · 0 评论 -
逆波兰计算器
上次所写的逆波兰计算器完全就是在云里雾里的情况下抄袭而成,这次经过多次的调试和自己动手写,明白了逆波兰运算器的原理,当然,例如TCPL书中所写的ungetch我是没有用到的。 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <math.h> /** * 创建...原创 2019-03-13 23:15:58 · 137 阅读 · 0 评论 -
TCPL 3-2
题目要求:编写一个escape(s, t), 将字符串t复制岛字符串s中,并再复制过程中将换行符、制表符等不可见字符分别转换位\n、\t等相应的可见的转义字符序列。要求使用switch语句。再编写一个具有相反功能的函数,在复制过程中将转义字符序列转换位实际字符。 void escape(char *s, char *t, int bit) //t被复制的变量, s存储复制结果的变量 { ...原创 2019-02-25 16:09:50 · 305 阅读 · 0 评论 -
TCPL 2-9
题目:在求对二的补码时,表达式x &= (x -1)可以删除x中最右边值为1的一个二进制位。请解释这样做的道理。用这一方法重写bitcount函数,以加快其执行速度。 int bitcount(unsigned x) { int nCount = 0; while(x != 0) { x &= x - 1; nCount++;...原创 2019-02-25 14:51:36 · 141 阅读 · 0 评论 -
strindex
该程序首先会选择一个字符串str,然后打印不包含该字符串的段落,以输入EOF结束 #include <stdio.h> #include <stdlib.h> #define MAXLINE 1000 int strindex(char *bufs, char *pattern); int getline(char *bufs, int limt); const c...原创 2019-02-25 10:57:24 · 1629 阅读 · 0 评论 -
TCPL 2-6
题目:编写一个函数setbits(x, p, n, y), 该函数返回对x执行下列操作后的结果值:将x中从第p位开始的n个(二进制)位设置为y中最右边n位的值,x的其余各位保持不变。 对这个题目有两个理解,将x中从p位开始的n位 设置 到 y最右边(返回结果以y为标准),或者将y中最右边的n位 设置 到x中 从p位开始 的n位(返回结果以x为标准)。 我将两种结果都写了出来。 下面是第...原创 2019-01-22 21:08:39 · 153 阅读 · 0 评论 -
TCPL 2-7
题目:编写一个函数invert(x, p, n),该函数返回对x执行下列操作后的结果值:将x种从中p位开始的n个(二进制)位求反(即,1变成0, 0变成1),x的其余各位保持不变。 下面是代码: unsigned invert(unsigned x, int p, int n) { return ~(~0 << n) << (p - 1) ^ x &...原创 2019-01-27 13:44:29 · 201 阅读 · 0 评论 -
逆波兰计算器
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #define MAXOP 100 //操作数或运算符的最大长度 #define NUMBER '0' //标识找到一个数 int getop(char *s); void push(double f); double ...转载 2019-01-15 11:17:21 · 155 阅读 · 0 评论 -
TCPL 2-4
题目:重新编写squeeze函数,将字符串s1中任何与字符串s2中字符匹配的字符都删除。 char* squzee(char *pstr_1, char *pstr_2) { int i = 0; int j = 0; int k = 0; for(; pstr_2[k] != '\0'; k++) { i = 0; f...原创 2019-01-12 14:58:56 · 158 阅读 · 0 评论 -
TCPL 2-3
题目:将字符串类型的十六进制数转化成整数类型的十进制数。 long htoi(char *pstr) { int i = 0; int nNums = 0; int nIdx = 0; long lSum = 0; if(pstr[i] == '-') { nIdx = -1; i++; } w...原创 2019-01-11 21:43:49 · 154 阅读 · 0 评论 -
TCPL 1-22
编写一个程序,把较长的输入行“折”成短一些的两行或多行。 #include <stdio.h> #define MAXCOL 10 #define TABINC 8 void printl(int pos); int exptab(int pos); int newline(int pos); int findline(int pos); char line[MAXCOL];...原创 2019-01-02 11:41:31 · 189 阅读 · 0 评论 -
TCPL 2-1
题目:确定signed和unsigned的范围 #include <stdio.h> #include <stdlib.h> #include <limits.h> int main() { printf("signed char min = %d\n", SCHAR_MIN); printf("signed char max = %d\n...原创 2019-01-10 15:17:43 · 191 阅读 · 0 评论 -
TCPL 4-12
题目:运用printd函数的设计思想编写一个递归版本的itoa函数。即通过递归调用把整数转换为字符串。 在这里,我先将itoa函数写了出来,然后再写了一下递归版本的,很显然,递归版本的代码量远远小于正常版本的。但是相应的也要付出一定的空间代价。 #include <stdio.h> #include <stdlib.h> #include <malloc.h&g...原创 2019-03-24 16:55:49 · 183 阅读 · 0 评论