c-c++
elimuzi
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C语言检测连接网卡状态
C语言检测连接网卡状态 有些客户程序里面的代码需要自己检测网卡状态,检查是否连接网线。需要提供函数给他们调用,检测网卡连接状态。//在<linux/ethtool.h>头文件中存在结构体`ethtool_value`,用于存放网卡连接状态。/* for passing single values */struct ethtool_value { __u32 cmd; __u32 data; // 表示网卡连接状态。};// 在<li原创 2021-02-05 08:58:14 · 4191 阅读 · 0 评论 -
linux c 中英文日期格式
函数说明setlocale位于locale.h头文件setlocale(LC_TIME,"zh_CN.UTF-8");1表示设置日期编码格式,这里设置为中文的日期格式strftime位于time.h头文件strftime格式化struct tm日期,受setlocale(LC_TIME,"zh_CN.UTF-8");的影响。测试#include <time.h>#include <locale.h>#include <stdio.h>/*获取当前日期*原创 2020-05-26 08:59:01 · 904 阅读 · 0 评论 -
tcpwrap.c:16:20: fatal error: tcpd.h: 没有那个文件或目录
手工编译vsftpd报错,提示tcpwrap.c:16:20: fatal error: tcpd.h: 没有那个文件或目录gcc -c postprivparent.c -idirafter dummyincgcc -c logging.c -idirafter dummyincgcc -c str.c -idirafter dummyincgcc -c netstr.c -idirafter dummyincgcc -c sysstr.c -idirafter dummyincgc原创 2020-05-22 19:25:29 · 1913 阅读 · 0 评论 -
字符串转浮点数atof函数的实现
#include <stdio.h>/*字符是否在某个区间范围内*/#define in_range(c, lo, up) ((unsigned char)c >= lo && (unsigned char)c <= up) /*十进制内字符*/#define isdigit(c) in_range(c, '0', '9...原创 2020-04-29 10:04:59 · 468 阅读 · 2 评论 -
c语言字典库的使用,实现键值对查找,以字符串为Key,以指针为Value
c语言字典库的使用,实现键值对查找,以字符串为Key,以指针为Valuedictionary库的使用dictionary库源码dictionary的接口说明dictionary使用测试dictionary库的使用前不久,一直在找一个c语言版的hash键值对库,找到一个dictionary库,是以字符串为key,以字符串为value的键值对库,但是我需要的是以字符串为key,以任意指针为valu...原创 2020-04-28 11:27:03 · 10211 阅读 · 5 评论 -
linux c 线程池库
主要由两个文件组成一个threadpool.h头文件和一个threadpool.c源文件组成。threadpool.c文件#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <assert.h>#include...转载 2020-04-27 16:06:41 · 882 阅读 · 5 评论 -
linuxc 函数的耗时测试
获取当前时间的微妙/** * 获取当前时间的微妙数*/long int GetMicrosecondCount(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec*1000000 + tv.tv_usec;}获取前后时间差#define GET_TIME(t, code) ...原创 2020-04-27 14:58:31 · 606 阅读 · 0 评论 -
设置线程高优先级
#ifdef HAVE_SCHED_H#include <sched.h>#endif void setCurrentThreadHighPriority(bool value) { // Start out with a standard, low-priority setup for the sched params. struct sched_param sp;...原创 2020-04-26 17:01:59 · 392 阅读 · 0 评论 -
struct timeval的处理(timeval比较及相减)
timeval结构体的处理函数timeval的大小比较timeval转为double类型的秒两个timeval类型之间的时间差timeval的大小比较/** ****************************************************************************** * @brief 时间比较 t1 == t2 返回0, t1 > ...原创 2020-04-22 09:47:28 · 7900 阅读 · 0 评论 -
使用snprintf实现itoa
发现linux c的stdlib.h中没有itoa,暂时使用snprintf代替实现。而snprintf在#include <stdio.h>中。#include <stdio.h>#include <stdlib.h>int itoa(int i, char * str, int maxlen) { return !str ? -1 : sn...原创 2020-04-17 21:04:34 · 328 阅读 · 0 评论 -
C语言使用cJson库解析json
使用C语言解析jsoncjson库对cjson库进一步封装调用测试案例cjson库在github或gitee上cjson,使用库中的cJSON.c与cJSON.h即可。以下是我使用cjson的案例仅供参考。我的cJosn使用案例对cjson库进一步封装对cjson库封装了几个函数,方便对json进行操作,以供参考根据json文件路径,将文件转为json对象cJSON * json_...原创 2020-04-09 16:07:07 · 1658 阅读 · 1 评论 -
gcc编译器预定义宏(__FILE__,__FUNCTION__,__LINE__)用于输出跟踪代码,定位代码行
__FILE__,__FUNCTION__,__LINE__使用案例如下,在编译时编译器会替换其值。用于更正#include <stdio.h>#include <stdlib.h>int main(int argc, char * argv[]){ char * lang = getenv("LANG"); // 获取本程序运行的语言环境 if ...原创 2020-04-08 11:25:28 · 2006 阅读 · 0 评论 -
linux环境变量、environ、getenv、setenv、unsetenv
linux环境变量linux环境变量shell获取环境变量环境变量相关命令环境变量名C获取环境变量linux环境变量每个进程运行都有自己的环境变量。也可以认为,shell及其在该shell中运行的子进程共用的变量,称为环境变量。一个进程的变量有很多,分为该进程的自定义变量,及其环境变量。shell获取环境变量环境变量相关命令命令说明set显示当前 Shell 所有变...原创 2020-04-08 09:52:52 · 2963 阅读 · 0 评论 -
const关键字
const关键字 const 限定一个对象为只读属性。 一级指针:(1)const char p 限定变量p为只读。这样如p=2这样的赋值操作就是错误的。 (2)const char *p p为一个指向char类型的指针,const只限定p指向的对象为只读。这样,p=&a或 p++等操作都是合法的,但如*p=4这样的操作就错了,因为企图改写这个已经被限定为只读属性的对象。 (原创 2016-09-04 19:26:28 · 347 阅读 · 0 评论 -
函数指针
#include<stdio.h>//定义函数指针类型,//compare表示指向形式为int (*)(int,int) 的指针;typedef int (*compare)(int,int) ;/*-------------------------------升序比较-------------------------------*/int compare_asc(int a ,i原创 2016-09-08 14:03:31 · 275 阅读 · 0 评论 -
C语言:贪吃蛇
代码#include<stdio.h>#include<windows.h>#include<time.h>#define FrameWidght 22#define FrameHeight 22short generateRandNumber(short a, short b) ;void posConsoleCursor(short x, short y) ;void hideCons原创 2016-11-27 17:17:27 · 743 阅读 · 0 评论 -
编程: p10252
编程: p10252题目Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation原创 2017-03-23 18:33:33 · 625 阅读 · 0 评论 -
C语言宏定义(常用宏定义)
C语言常用宏定义常用宏定义数值相关的宏定义字符相关的宏定义byte相关的宏定义bit相关的宏定义数组与结构体相关的宏定义对齐的宏定义常用宏定义数值相关的宏定义闰年的判断 ,年份可以整除4并且不能整除100,或者可以整除400,则为闰年;#define IS_LEAP_YEAR(y) (((((y) % 4) == 0) &amp;amp;&amp;amp; (((y) % 100) != 0)) ...原创 2018-11-07 12:50:10 · 5063 阅读 · 0 评论 -
C语言宏定义(#与##)
宏定义中的#与##宏定义中#与##宏定义中的#一般用法下面来点复杂的宏定义中#与##宏定义中的#一般用法例如 #define TOSTRING(s) #s#将s转为字符串#cinlude<stdio.h>#define TOSTRING(s) #sint main(){ const char *p1 = TOSTRING(123); const char *p...原创 2019-05-09 23:31:39 · 2234 阅读 · 0 评论 -
数组中a与&a的区别
代码int main(){ int a[5]={1,2,3,4,5}; int *ptr=(int *)(&a+1); printf("%d,%d",*(a+1),*(ptr-1)); return 0 ;}结果:分析 (a+1)我们都知道,(a+1)=&a[1] , *(a+1) = a[1] ,这个1代表的是sizeof(int) 但是(&原创 2016-09-04 14:37:26 · 477 阅读 · 0 评论
分享