char

Python 调用 C++ 代码

别说谁变了你拦得住时间么 提交于 2020-02-28 19:52:32
C++ extern "C" { float test_func (char *a, float b, int c); } float test_func (char *a, float b, int c) { float d = 3.14; return d; } 编译动态库 g++ pyclib.cpp -fPIC -shared -o libpyc.so Python from ctypes import * pyclib = cdll.LoadLibrary('./libpyc.so') pyclib.test_func.argtypes = [c_char_p, c_float, c_int] pyclib.test_func.restype = c_float a = 'c' b = 1.0 c = 1 d = pyclib.test_func(a, b, c) 参考文献: https://www.jianshu.com/p/edb8698d1374 https://stackoverflow.com/questions/43317409/ctypes-argumenterror-dont-know-how-to-convert-parameter https://docs.python.org/zh-cn/3.7/library/ctypes.html https:/

C语言 strncmp

时间秒杀一切 提交于 2020-02-28 19:45:06
C语言 strncmp #include <string.h> int strncmp(const char *s1, const char *s2, size_t n); 功能:比较 s1 和 s2 前n个字符的大小,比较的是字符ASCII码大小。 参数: s1:字符串1首地址 s2:字符串2首地址 n:指定比较字符串的数量 返回值: 相等:0 大于: > 0 小于: < 0 案例 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> int main(void) { char ch1[] = "hello world"; char ch2[] = "hallo world"; // 两个有限字符串比较 int value = strncmp(ch1, ch2); // 返回为1不相等 printf("%d\n", value); return 0; } strncmp 使用案例:使用函数 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h>

C语言 strchr

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-28 19:41:29
C语言 strchr #include <string.h> char *strchr(const char *s, int c); 功能:在字符串s中查找字母c出现的位置 参数: s:字符串首地址 c:匹配字母(字符) 返回值: 成功:返回第一次出现的c地址 失败:NULL 案例 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <time.h> int main(void) { char ch[] = "hello world"; char c = 'w'; // 查找字符串 char* p = strchr(ch, c); printf("%s\n", p); return 0; } strchr 使用案例 来源: https://www.cnblogs.com/xiangsikai/p/12378561.html

【leetcode】【medium】79. Word Search

戏子无情 提交于 2020-02-28 18:51:05
79. Word Search Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. Example: board = [ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ] Given word = " ABCCED ", return true . Given word = " SEE ", return true . Given word = " ABCB ", return false . 题目链接: https://leetcode-cn.com/problems/word-search/ 思路 这道题很简单,但是写出来的代码一直在运行时间上表现不好。 第一版代码是这样的: class Solution { public: vector

一个AT命令处理小函数

孤街醉人 提交于 2020-02-28 18:43:32
问题描述 对于AT命令的回复,是一个字符串,如果处理该字符串,每次收到字符串都处理一次非常的麻烦,写一个函数来处理AT命令,能大大减少这种麻烦。 函数 /* * 取两个分隔符之间的子串 * str 原始字符串 * separator1 第一个分隔符 * separator2 第二个分隔符 * num 字符串出现几次时,作为第一个分隔符的位置。 * substr 取出的两个分隔符间的子串,从0起数。"+QMTRECV: 0,0,"Hello",hello world" */ uint8_t get_sub_str(char * str,char * separator1,char * separator2,int8_t num, char * substr) { int8_t i; char *p1,*p2; p1 = str; for(i = 0; i<=num; i++) { p1 = strstr(p1,separator1); if(p1 == NULL) return 1; p1++; } p2 = strstr(p1,separator2); if(p2 == NULL) return 2; memcpy(substr,p1,p2-p1); return 0; } 将AT命令返回的字符串赋给str,取两个分隔符之间的子串,将该子串放到substr中返回

分析单片机堆栈,分享个人理解

╄→尐↘猪︶ㄣ 提交于 2020-02-28 18:15:17
看关于单片机方面的书籍的时候,总是能看到别人说的一些堆栈啊什么的操作,之前看到这个术语就直接跳过,没想到去探究单片机内部的原理。但是最近课程学习微机原理这门课,需要我们写汇编程序,汇编里面经常遇到堆栈这个东西,所以就找了个时间把堆栈给彻底的搞一下。 如果了解一点汇编编程话,就可以知道,堆栈是内存中一段连续的存储区域,用来保存一些临时数据。通常用来保存CALL指令调用子程序时的返回地址,RET指令从堆栈中获取返回地址。中断指令INT调用中断程序时,将标志寄存器值、代码段寄存器CS值、指令指针寄存器IP值保存在堆栈中。 堆栈也可以用来保存其他数据。 堆栈操作由PUSH,POP两条指令来完成; 堆栈操作的操作数均为子类型(两个字节)进行操作。 程序内存可以分为几个区,栈区(stack),堆区(Heap),全局区(static),文字常亮区,程序代码区。 程序编译之后,全局变量,静态变量已经分配好内存空间,在函数运行时,程序需要为局部变量分配栈空间,当中断来时,也需要将函数指针入栈,保护现场,以便于中断处理完之后再回到之前执行的函数。 栈是从高到低分配,堆是从低到高分配。 我们一般说的堆栈指的栈。堆栈又分硬堆栈和软堆栈,硬堆栈即SP,从片内RAM的顶部向下生长。软堆栈在硬堆栈跟全局变量区之间的空间,C51函数调用通过R0-R7和栈来实现。 为什么单片机启动时

BP算法

时光总嘲笑我的痴心妄想 提交于 2020-02-28 17:40:56
# define _CRT_SECURE_NO_WARNINGS # include "string.h" # include "stdio.h" /*BP算法的实现 *@auther:ck */ /*函数声明*/ int Index ( char * Buffer , char * buffer , int pos , int Count ) ; int Strlen ( char * Buffer ) ; /*main*/ void main ( void ) { int index ; int count ; char Buffer [ 20 ] = "acfgyhgtuoitmn" ; char buffer [ 6 ] = "tuoit" ; count = Strlen ( buffer ) ; index = Index ( Buffer , buffer , 2 , count ) ; for ( int i = 0 ; i < count ; i ++ ) { printf ( "%c" , Buffer [ index ++ ] ) ; } printf ( "\n" ) ; system ( "pause" ) ; } /* *@param:pos:need found position *@return:if found return position

Linux系统中软件简单License的实现

旧时模样 提交于 2020-02-28 15:48:56
概述 目前,很多商用应用系统是运行在Linux系统之上的,为了维护开发者利益,有必要为软件添加license功能,防止软件被盗用和挪用。本文探讨如何在Linux软件中添加license功能,用到的算法是MD5算法。 关键字: MD5 一 目的和思路 设置License就是要将软件和运行该软件的机器进行简单“绑定”,该软件只能在某台指定机器上使用,如果将该软件挪动到其他机器上则无法运行。 根据以上目的,那么思路就很清晰,则我们需要读取该指定机器的某些特征,这里我们只抓取两个特征,即CPU特征和机器MAC地址。 这样,我们需要一个获得机器特征的程序,一个生成license的程序以及在所要加license的程序中嵌入检查license的代码。生成license程序可以是在windows操作系统下编写,也可以在Linux系统下编写,本文只讨论后面一种。 二 关键技术 这里的三个关键技术是获得本机的CPU信息、获得网卡MAC地址信息以及MD5加密。 1. 获得CPU信息 兼容x86的CPU的信息存储在数据结构: struct cpuinfo_x86 { __u8 x86; /* CPU family */ __u8 x86_vendor; /* CPU vendor */ __u8 x86_model; __u8 x86_mask; char wp_works_ok; /* It doesn

Codeforces Round #541 (Div. 2)题解

喜你入骨 提交于 2020-02-28 15:41:59
不知道该更些什么 随便写点东西吧 https://codeforces.com/contest/1131 ABC 太热了不写了 D 把相等的用并查集缩在一起 如果$ x<y$则从$ x$往$y$连边 如果并查集内有边或边构成环则无解 否则做一遍拓扑输出答案 #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define rt register int #define ll long long using namespace std; inline ll read(){ ll x = 0; char zf = 1; char ch = getchar(); while (ch != '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') zf = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf; } void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);} void

C++四种类型转换

两盒软妹~` 提交于 2020-02-28 13:32:45
C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是: TYPE b = (TYPE)a C++风格的类型转换提供了4种类型转换操作符来应对不同场合的应用。      static_cast 静态类型转换。如int转换成char reinterpreter_cast 重新解释类型    dynamic_cast 命名上理解是动态类型转换。如子类和父类之间的多态类型转换。      const_cast, 字面上理解就是去const属性。 4种类型转换的格式: TYPE B = static_cast<TYPE> (a) 一般性介绍 1)static_cast<>() 静态类型转换, 编译的时c++编译器会做类型检查 ; 基本类型能转换 但是不能转换指针类型 2)若不同类型之间, 进行强制类型转换 ,用reinterpret_cast<>() 进行重新解释 3)一般性结论: C语言中 能隐式类型转换的,在c++中可用 static_cast<>()进行类型转换。因C++编译器在编译检查一般都能通过; C语言中不能隐式类型转换的,在c++中可以用 reinterpret_cast<>() 进行强行类型 解释。总结:static_cast<>()和reinterpret_cast<>() 基本上把C语言中的 强制类型转换给覆盖 reinterpret_cast<>(