C语言
文章平均质量分 88
Seth423
这个作者很懒,什么都没留下…
展开
-
MD5的C实现及中间计算数据(学习记录 2020/1/8)
研二MD5今年的目标是要实现20个以上的标准,MD5是第一个。MD5的相关标准我参考的是RFC1321,但RFC好像并不是真正意义上的标准文件,这个之后再去研究。根据文档上对算法的描述,我编写出了如下代码:#include <stdio.h>#include <stdlib.h>#include <string.h>#define IN#define OUT#define LOGE printf#define LOGD printf#defi原创 2021-01-08 19:14:05 · 221 阅读 · 1 评论 -
C程序设计语言 5-10
练习5-10 编写程序expr,以计算从命令行输入的逆序波兰表达式的值,其中每个运算符或操作数用一个单独的参数表示。例如,命令:expr 2 3 4 + * 将计算表达式2*(3+4)的值。给结果之前先记录一下书上这个牛逼的程序:P101,允许输入参数的模式匹配程序。#include <stdio.h>#include <string.h>#define MAXLINE 1000int getline(char *line, int max);int mai原创 2020-07-17 13:39:49 · 831 阅读 · 0 评论 -
C程序设计语言 5-9
练习5-9 用指针方式代替数组下标方式改写函数day_of_year和month_day。这种方法可以给指针数组赋值。#include <stdio.h>void main() { int* a[2]; int m[] = { 8, 99, 10 }; int n[] = { 11, 22, 33, 44 }; a[0] = m; a[1] = n; printf("a[1]:%d\n", a[1][1]);}我的想法是,指原创 2020-07-10 16:37:30 · 605 阅读 · 0 评论 -
C程序设计语言 5-8
练习5-8 函数day_of_year和month_day中没有进行错误检查,请解决该问题。#include <stdio.h>#define PPP printf("what does it for?\n");static char daytab[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}.原创 2020-07-08 17:12:00 · 519 阅读 · 0 评论 -
C程序设计语言 5-7
练习5-7 重写readlines,将输入的文本行存储到由main函数提供的一个数组中,而不是存储到调用alloc分配的存储空间中。该函数的运行速度比改写前快多少?#include <stdio.h>#include <string.h>#define MAXLINES 5000char *lineptr[MAXLINES];int readlines(char *lineptr, char *allocation, int maxlines);void wri.原创 2020-07-07 20:35:15 · 603 阅读 · 0 评论 -
C程序设计语言 5-5
练习 5-5 实现库函数strncpy、strncat和strncmp,它们最多对参数字符串中的前n个字符进行操作。例如,函数strncpy(s,t,n)将t中最多前n个字符复制到s中。更详细的说明请参见附录B。#include <stdio.h>void my_strncpy(char *, char *, int n);void my_strcat(char *, char *, int n);int my_strncmp(char *, char *, int n);i.原创 2020-06-19 10:25:01 · 349 阅读 · 0 评论 -
C程序设计语言 5-4
练习5-4 编写函数strend(s, t)。如果字符串t出现在字符串s的尾部,该函数返回1,否则返回0。#include <stdio.h>int my_strend(char *, char *);int main() { char s[20], t[10]; printf("please input string s, while s has no more than 10 chars.\n"); scanf("%s", s); printf("please.原创 2020-06-18 16:39:42 · 657 阅读 · 0 评论 -
C程序设计语言 5-3
练习5-3 用指针方式实现第2章中的函数strcat。函数strcat(s, t)将t指向的字符串复制到s指向的字符串的尾部。#include <stdio.h>int my_strcat(char *, char *);int main(){ char s[20], t[10]; printf("please input string s, while s has no more than 10 chars.\n"); scanf("%s", s); printf(.原创 2020-06-18 15:23:08 · 775 阅读 · 4 评论 -
C程序设计语言 5-2
练习5-2 模仿函数getint的实现方法,编写一个读取浮点数的函数getfloat。getfloat函数的返回值应该是什么类型?返回值还是int不用变。#include <stdio.h>#include <ctype.h>#define SIZE 10#define BUFSIZE 10int getch();void ungetch(int c);int getfloat(float *pn);char buffer[BUFSIZE];int b原创 2020-06-18 12:05:43 · 756 阅读 · 0 评论 -
C程序设计语言 5-1
练习5-1 在上面的例子中,如果符号+或-的后面紧跟的不是数字,getint函数将把符号视为数字0的有效表达方式。修改该函数,将这种形式的+或-号重新写回到输入流中。照着书上的程序抄的,结果一直有错。编译可以顺利进行,但是每次一输入字母程序就直接返回。后来发现书上的程序有点小错,在getint函数中第一个条件语句if下面不应该有ungetch函数出现。因为如果此时输入的是字母,ungetch函数会把字母输入到自己定义的缓冲区中,之后调用getch就只会得到刚刚放进去的字母,并一直返回。把这行删掉..原创 2020-06-18 00:10:18 · 770 阅读 · 0 评论 -
C头文件 header 大全
C 语言头文件大全,我要的都能在里面找到,分享出来。链接:https://pan.baidu.com/s/1WT-5uZljPib1vg4p5PULGA提取码:9ix0原创 2020-06-03 23:31:22 · 1098 阅读 · 0 评论 -
C程序设计语言 4-14
练习4-14 定义宏swap(t,x,y)以交换t类型的两个参数。(使用程序块结构会对你有所帮助。)少使了一个参数,也能完成题意。#include <stdio.h>#define swap(x, y) \ { \ x = x + y; \ y = x - y; \ x = x - y; \ } \ int main(){ int a = 12, b = 13; swap(int, a, b); printf("%d, %d\n",.原创 2020-06-01 18:02:04 · 293 阅读 · 0 评论 -
C程序设计语言 4-13
练习4-13 编写一个递归版本的reversed(s)函数,以将字符串s倒置;递归顺序如图, 有一个含四个字符的字符串,递归到最底层的时候先互换cd两个字符,然后回到上一层,交换bdc三个字符,然后再回到上一层,交换adcb四个字符,此时字符串已完成逆序。虽然到第四章还没有学到指针,但是个人感觉不得不用指针完成此问题。#include <stdio.h>void recursion_reverse(char *s, int len);int str_len(char *.原创 2020-06-01 17:43:14 · 338 阅读 · 2 评论 -
C程序设计语言 4-12
练习4-12 运用printd函数的设计思想编写一个递归版本的itoa函数,即通过递归调用把整数转换为字符串。递归真挺难的。。。#include <stdio.h>void recursion_itoa(int d, char *ptr, char *s);void reverse(char *s, char len);int int_len(int d);int main(){ int input, len; char s[6]; char *p = s; .原创 2020-06-01 15:35:47 · 325 阅读 · 0 评论 -
C程序设计语言 4-10
练习4-10 另一种方法是通过getline函数读入整个输入行,这种情况下可以不使用getcha和ungetch函数。请运用这一方法修改计算器程序。#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include "calc.h"#define MAXLEN 100#define MAXOP 100int getop(char s[], c原创 2020-05-16 01:19:55 · 378 阅读 · 0 评论 -
C程序设计语言 4-9
练习4-9 以上介绍的getch和ungetch函数不能正确地处理压回的EOF。考虑压回EOF时应如何处理?请实现你的方案。#include <stdio.h>#define BUFSIZE 10#include "calc.h" char buf[BUFSIZE];int bufp = 0; int getch(void){ return (bufp > 0) ? buf[--bufp] : getchar();} void ungetch(int c).原创 2020-05-08 23:08:25 · 403 阅读 · 0 评论 -
C程序设计语言 4-8
练习4-8 假定最多只压回一个字符。请相应地修改getch和ungetch这两个函数。#include <stdio.h>#include "calc.h"int buf = EOF;int getch(void){ int temp = buf; buf = EOF; return (temp != EOF) ? temp : getchar();}vo...原创 2020-05-06 23:54:48 · 299 阅读 · 0 评论 -
C程序设计语言 4-7
练习4-7 编写一个函数ungets(s),将整个字符串s压回到输入中。ungets函数需要使用buf和bufp吗?它能否仅使用ungetch函数?需要间接使用buf和bufpvoid ungets(char s[]){ int len = strlen(s); while (len-- > 0) { ungetch(s[len])...原创 2020-05-06 23:33:10 · 218 阅读 · 0 评论 -
C程序设计语言 4-6
练习4-6 给计算机程序增加处理变量的命令(提供26个具有单个英文字母变量名的变量很容易)。增加一个变量存放最近打印的值。主函数:#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include "calc.h"#define MA...原创 2020-05-06 23:13:59 · 438 阅读 · 0 评论 -
C程序设计语言 4-5
练习 4-5给计算器程序增加访问 sin、exp 与 pow 等库函数的操作。有关这些库函数的详细信息,参见附录 B.4 节中的头文件math.h。函数strcmp在比较结果相等的时候返回值是0不是1!!!一开始在调用这里的时候一直以为返回值会是1,怎么算也算不出来,想了好久。主函数——main.c#include <stdio.h>#include <std...原创 2020-04-29 23:08:08 · 489 阅读 · 0 评论 -
C程序设计语言 4-4
练习4-4 在栈操作中添加几个命令,分别用于在不弹出元素的情况下打印栈顶元素;复制栈顶元素;交换栈顶两个元素的值。另外增加一个命令用于清空栈。#include <stdio.h>#define MAXVAL 100int sp = 0;double val[MAXVAL];void push(double f){ if (sp < MAXVAL) v...原创 2020-04-29 00:47:00 · 466 阅读 · 0 评论 -
C 程序设计语言 4-3
#include <stdio.h>#include <stdio.h>#include <stdlib.h>#define MAXOP 100#define NUMBER '0'int getop(char []);void push(double);double pop(void);int main(){ int type; ...原创 2020-04-23 00:08:44 · 839 阅读 · 0 评论 -
C程序设计语言 4-2
练习4-2 对atof函数进行扩展,使它能够处理形如123.45e-6的科学计数法,其中浮点数后面可能会紧跟一个e或E以及一个指数(可能有正负号)。#include <stdio.h>#include <ctype.h>#define MAXLEN 100double atof(char s[]);int main(){ int c, i = 0;...原创 2020-04-22 17:50:02 · 372 阅读 · 0 评论 -
C程序设计语言 4-1
练习4-1 编写函数strrindex(s,t),它返回字符串t在s中最右边出现的位置。如果s中不包含t,则返回-1。#include <stdio.h>#include <string.h>#define MAXLEN 100int strrindex(char s[], char t[]);int main(){ int c, i; cha...原创 2020-04-19 00:22:36 · 730 阅读 · 0 评论 -
C程序设计语言 3-6
练习3-6 修改itoa函数,使得该函数可以接收三个参数。其中,第三个参数为最小字段宽度。为了保证转化后所得结果至少具有第三参数指定的最小宽度,必要时应在所得结果的左边添加一定的空格。#include <stdio.h>#include <string.h>#define MAXLEN 32void itoa(int n, char s[], int l);...原创 2020-04-18 22:41:55 · 442 阅读 · 0 评论 -
C程序设计语言 3-5
练习 3-5编写函数 itob(n, s, b),将整数 n 转换为以 b 为底的数,并将转换结果以字符的形式保存到字符串 s 中。例如,itob(n, s, 16)把整数 n 格式化成十六进制整数保存在 s 中。一开始想的是设置一个进制转换表,比如16进制得到[0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f],进制得到[0,1,2,3,4,5,6,7,8,9,a,b,c,d...原创 2020-04-18 22:20:35 · 542 阅读 · 0 评论 -
C程序设计语言 3-4
练习 3-4在数的对二的补码表示中,我们编写的 itoa 函数不能处理最大的负数,即n 等于-2 字长-1的情况。请解释其原因。修改该函数,使它在任何机器上运行时都能打印出正确的值。错误在于补码表示中正数取值范围比复数小一。补码的表示即为模运算表示法。举个简单的例子,假如计算机表示的位数为3位,即000~111,如果不要求表示负数,那么000~111换算成十进制即为0~7,即计算机只能表示0...原创 2020-04-17 18:10:18 · 518 阅读 · 0 评论 -
C程序设计语言 3-3
练习 3-3编写函数 expand(s1, s2),将字符串 s1 中类似于 a-z 一类的速记符号在字符串 s2 中扩展为等价的完整列表 abc…xyz。该函数可以处理大小写字母和数字,并可以处理 a-b-c、a-z0-9 与-a-z 等类似的情况。作为前导和尾随的-字符原样排印。写完都不想看了,改的太久了。。。#include <stdio.h>#include ...原创 2020-04-17 16:13:53 · 315 阅读 · 1 评论 -
C程序设计语言 3-2
练习 3-2编写一个函数 escape(s, t),将字符串 t 复制到字符串 s 中,并在复制过程中将换行符、制表符等不可见字符分别转换为\n、\t 等相应的可见的转义字符序列。要求使用 swich 语句。再编写一个具有相反功能的函数,在复制过程中将转义字符序列转换为实际字符。#include <stdio.h>#define MAXLEN 100void esca...原创 2020-04-16 11:45:01 · 398 阅读 · 0 评论 -
C程序设计语言 3-1
练习3-1 在上面有关折半查找的例子中,while循环语句内共执行了两次测试,其实只要一次就足够(代价是将更多的测试在循环外执行)。重写该函数,使得在循环内部只执行以此测试。比较两种版本函数的运行时间。我一开始是没想出来的,所以去网上看了看,发现网上有些代码无法运行但思路是对的,所以重新改了改发出来。以下是原文链接:https://blog.csdn.net/warmars/arti...原创 2020-04-16 10:29:40 · 457 阅读 · 0 评论 -
C程序设计语言 2-10
练习2-10 重新编写将大写字母转换为小写字母的函数lower,并用田间表达式替代其中的if-else结构。#include <stdio.h>#define MAXLEN 100void lower(char s[]);int main(){ int i, c; char s[MAXLEN]; i = 0; printf("Please input s...原创 2020-04-15 22:16:33 · 322 阅读 · 0 评论