随笔分类 -  linux下C编程

摘要:实验环境fedora33 Qt5.12 背景 哈夫曼编码 每个结点包含了字符和对应的权值等信息,最好记录在文件里,每次运行代码从文件里读取结点信息 输入结点信息 1 #include <stdio.h> 2 3 typedef struct 4 { 5 int weight; 6 char myva 阅读全文
posted @ 2020-12-07 06:54 saintdingtheGreat 阅读(323) 评论(0) 推荐(0)
摘要:实验环境 fedora33 Qt5.12 喜欢C语言是因为他的广泛用途,但是今儿有点想爆粗口,姑爷爷我刚心情好点想学学哈夫曼编码写个小程序,结果跟我这拱火劲儿的 执行完scanf函数之后,后面的命令居然都不执行了!要是说写段入侵北美防空司令部的代码,出点问题咱也能理解,确实是不太容易,一他妈的输入字 阅读全文
posted @ 2020-12-07 02:54 saintdingtheGreat 阅读(1007) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <hiredis/hiredis.h> int main() { redisContext *c = redisConnect("127.0.0.1", 6379); if (c == NULL || c->err) { if (c) { pr 阅读全文
posted @ 2020-11-19 03:43 saintdingtheGreat 阅读(324) 评论(0) 推荐(0)
摘要:上机环境ubuntu20.0.4 QtCreator 准备活动,安装libmongoc 和libbson 最好sudo apt 安装 mongodb,这样我们就能获得 mongoc.h 别忘了,在QtCreator选择根目录,右键点击Add Library添加libmongoc.so和libbson 阅读全文
posted @ 2020-11-19 01:51 saintdingtheGreat 阅读(636) 评论(0) 推荐(0)
摘要:上机环境 ubuntu 20.04 Qt 5.12 有时候写博的目的是分享自己踩过的坑,为同样喜爱编程的朋友树立警示牌,以免他们热情的心受到伤害。 我一直以来认为C/C++是黑客的标配武器,因此对这两种语言有种膜拜的心情,好的语言当然要拿来连接数据库,C也不例外。当你找到mysql的官方文档,他们依 阅读全文
posted @ 2020-11-18 17:46 saintdingtheGreat 阅读(1614) 评论(1) 推荐(0)
摘要:错误处理 头文件 #include<error.h> 这样一来,errno就是个数据类型 errno=ECONNABORTED|EINTR char* s="xxxxxx" perror(s); exit(-1); read函数 返回值: >0,读到的文件字节长度 =0 (文件读到‘\o',管道中读 阅读全文
posted @ 2020-02-07 20:45 saintdingtheGreat 阅读(167) 评论(0) 推荐(0)
摘要:数据发到网络环境通常通过交换机,再由交换机转发至路由器 但凡提到套接字,必定有两端:数据的发送端和接收端, ip地址在网络环境中可以唯一的表示一台主机,ip+端口号可以在网络环境中唯一标识一个进程。 socket通信原理: 套接字是linux操作系统中的一种文件类型 伪文件 linux中有7种文件类 阅读全文
posted @ 2020-02-06 03:53 saintdingtheGreat 阅读(308) 评论(0) 推荐(0)
摘要:协议 乃是数据传输时要遵守的格式要求 两种常见的程序架构是C/S 和B/S架构 C/S :优点,性能稳定,协议选用灵活,适用于大量数据缓存,尤以游戏较为常见 安装在用户电脑上,可能会对用户安全造成影响 开发效率方面,开发团队需编写服务端和客户端两端代码,联合调试是一场噩梦 B/S: 减少了厂商植入恶 阅读全文
posted @ 2020-02-04 22:34 saintdingtheGreat 阅读(167) 评论(0) 推荐(0)
摘要:上机环境linux mint下 Qt5.11 一例孤儿进程代码的演示 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<fcntl.h> 阅读全文
posted @ 2020-01-12 13:24 saintdingtheGreat 阅读(740) 评论(0) 推荐(0)
摘要:实验环境linux mint下面 QT5.11 execlp失败时返回 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include<sys/types.h> int main() { pid_ 阅读全文
posted @ 2020-01-11 15:30 saintdingtheGreat 阅读(683) 评论(0) 推荐(0)
摘要:一个典型的例子 #include <stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> #include<sys/types.h> int main() { pid_t pid; pid_t pid2; int var 阅读全文
posted @ 2020-01-11 13:49 saintdingtheGreat 阅读(175) 评论(0) 推荐(0)
摘要:信号的定义 信号只不过是一个标志信息,并不能携带大量数据,进程会从内核收到信号,并按照约定执行一段代码体(响应信号),再继续执行其他代码,实际上这样一来,信号是一种软中断 严格地说进程A不能直接给进程B发送信号,而是借助内核完成信号的发送,同样进程B也是通过内核完成对信号的处理 信号四要素 编号 名 阅读全文
posted @ 2020-01-08 12:22 saintdingtheGreat 阅读(332) 评论(0) 推荐(0)
摘要:一个进程控制块,大体分下列三个内容: 进程描述信息 进程运行状态/调度信息 进程资源信息(进程所在存储器的地址信息,文件系统以及打开的文件信息) cpu现场信息;中断后保存寄存器信息和堆栈信息,以便下次回到断点后可以继续执行 进程通过fork()函数产生,其返回一个整型的进程号,在一段代码体中,通常 阅读全文
posted @ 2020-01-08 02:27 saintdingtheGreat 阅读(244) 评论(0) 推荐(0)
摘要:环境变量 **environ #include<stdio.h> #include<stdlib.h> #include<unistd.h> void main() { extern char **environ; for(int i=0;environ[i]!=NULL;i++) //for(in 阅读全文
posted @ 2020-01-07 23:03 saintdingtheGreat 阅读(113) 评论(0) 推荐(0)
摘要:实验环境linux mint 开发平台 Qt5.11 总体思想,linux C的文件目录相关函数有 mkdir rmdir opendir readdir 文件目录指针类型 DIR* dirent代表系统文件目录相关的结构体,其中属性d_type文件类型 d_name文件名或目录名DT_DIR代表文 阅读全文
posted @ 2020-01-07 03:18 saintdingtheGreat 阅读(1786) 评论(0) 推荐(1)
摘要:读取(open)文件并写入(write)另一个文件 #include <stdio.h> #include<stdlib.h> #include<string.h> #include<fcntl.h>.h> int main() { int fd1=open("/home/cpc/Documents 阅读全文
posted @ 2020-01-06 02:05 saintdingtheGreat 阅读(544) 评论(0) 推荐(0)
摘要:切到文件项目下 gcc *.c -o app -g 编译所有.c文件 生成文件 名为app -g添加调试信息 执行生成的文件app ./app 源文件:duwa.c #include <stdio.h> #include<stdlib.h> void main() { char *words="每当 阅读全文
posted @ 2020-01-02 15:20 saintdingtheGreat 阅读(350) 评论(0) 推荐(0)
摘要:服务端 其代码如下 #include <stdio.h> #include<stdlib.h> #include<sys/socket.h> #include<unistd.h> #define SERV_PORT 9898 #define SERV_IP "127.0.0.1" #include< 阅读全文
posted @ 2019-12-31 12:57 saintdingtheGreat 阅读(335) 评论(0) 推荐(0)
摘要:上机环境centos7下 Qt5.11 gcc 一些简单的函数封装 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> struct coach { char name[60]; int age; }; str 阅读全文
posted @ 2019-12-25 20:26 saintdingtheGreat 阅读(226) 评论(0) 推荐(0)
摘要:重要意义:间接赋值的意义,实现了模块的功能划分,实现了软件作品的分层,使得模块接口和信息系统得以实现。 所谓二级指针就是指向指针的指针,其声明形式如下 int *p=NULL int **p1=NULL; p1=&p; 一级指针*运算,从所指向内存空间取出数值(类比:一级指针是藏宝图,所指向的内存空 阅读全文
posted @ 2019-12-17 13:26 saintdingtheGreat 阅读(1368) 评论(0) 推荐(0)