size_t

OpenCV using cvImageCreate() with grayscale image fails, and resizing usually fails

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have such code that is loading grayscale image from buffer 1byte, 8bits bitmap. Then it resizes this image. int resizeBitmap(const unsigned char *inData, const size_t inDataLength, const size_t inWidth, const size_t inHeight, const int bitDepth, const int noOfChannels, unsigned char **outData, size_t *outDataLength, const size_t outWidth, const size_t outHeight) { // create input image IplImage *inImage = cvCreateImage(cvSize(inWidth, inHeight), bitDepth, noOfChannels); cvSetData(inImage, inData, inImage->widthStep); // show input image

Setting up Mysql++ in linux

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to connect to a mysql database with C++ in linux. On my local machine I am running Ubuntu, and installed the mysql server and client packages: sudo apt-get install mysql-server mysql-client I came across Mysql++ but have some problems when running ./configure from their binary package. The error says: checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql

CFRelease crash in iOS10

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Below is my code, which used to work fine till iOS 9. - (NSData *)encryptWithDataPublicKey:(NSString*)data keyTag:(NSString*)tag { SecKeyRef publicKey = NULL; NSData *publicTag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag]; [queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(_

Read files separated by tab in c

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am really new to C, and the reading files thing drives me crazy... I want read a file including name, born place and phone number, etc. All separated by tab The format might be like this: Bob Jason Los Angeles 33333333 Alice Wong Washington DC 111-333-222 So I create a struct to record it. typedef struct Person{ char name[20]; char address[30]; char phone[20]; } Person; I tried many ways to read this file into struct but it failed. I tired fread: read_file = fopen("read.txt", "r"); Person temp; fread(&temp, sizeof(Person), 100, read_file);

C语言学习笔记04――程序在内存中的分布以及内存越界问题

匿名 (未验证) 提交于 2019-12-03 00:22:01
C语言程序在内存中的分布: #include <stdio.h> char bss[1024*1024]; int main() { return 0;} 现在来看看程序的可执行文件大小 定义 char bss[1024*1024]={0};也是这个结果 可以看到 bss的大小并没有1MB 说明未初始化的全局变量不占程序文件的存储空间 #include<stdio.h> char data[1024*1024]={1}; int main() {return 0;} 运行结果: char* p = "12345" 如何使用堆内存: void *malloc(size_t size); void free(void *ptr); 举个例子: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main() { printf("%d\n",getpid()); //得到进程id char* p = malloc(sizeof(char)*10); char str1[7] = "123avbd"; char* str2 = "101"; printf("&p:%p\np:%p\n",&p,p); printf("str1:%p\nstr2:%p\n",str1

size_t――为什么支持size_t,何时使用size_t?

匿名 (未验证) 提交于 2019-12-02 23:56:01
许多C/C++文件中都会出现类型 size_t ,比如在bitcoin源码中,有这样的一个函数: size_t strnlen( const char *start, size_t max_len) { const char *end = (const char *)memchr(start, '\0', max_len); //memchr函数从start开始寻找第一个出现字符'\0'的位置并返回 return end ? (size_t)(end - start) : max_len; //const char的长度吧,为啥要这样写,为什么要单独写一个文件啊,NOTE } 该函数完成了返回 const char* 类型 start 代表的串的长度,返回值被设置为 size_t 类型。这是 size_t 经常被使用的一个场景“ 数组可能的长度 。 另一个使用场景就是函数 memcpy (其实本质上是一样的,都是表示 内存中 数据的多少)。 memcpy 的原型 void* memcpy(void*to,const void*from,size_t n) 。需要复制的字节数被设置为 size_t 类型,这是 数据块的大小 。 于是,会给人一种感觉,这种工作 int 也可以完成,如果说需要排除负数, unsigned int 也可以完成。为什么要多此一举引入 size_t 呢? 另外

linux编程必备函数

匿名 (未验证) 提交于 2019-12-02 21:59:42
1.memcpy 原型:void *memcpy(void*dest, const void *src, size_t n); (1)memcpy用来做内存拷贝,你可以拿它拷贝任何数据类型的对象,可以指定拷贝的数据长度; (2)将s中第14个字符开始的4个连续字符复制到d中。(从0开始) char * s="Golden Global View";   char d[20]; memcpy(d,s+14,4);//从第14个字符(V)开始复制,连续复制4个字符(View) (3)如果目标数组destin本身已有数据,执行memcpy()后,将覆盖原有数据(最多覆盖n)。如果要追加数据,则每次执行memcpy后,要将目标数组地址增加到你要追加数据的地址。 2. fopen 函数原型:FILE * fopen(const char * path, const char * mode); (1)返回值:文件顺利打开后,指向该流的文件指针就会被返回。如果文件打开失败则返回 NULL,并把错误代码存在error中。 (2)一般而言,打开文件后会做一些文件读取或写入的动作,若打开文件失败,接下来的读写动作也无法顺利进行,所以一般在 fopen() 后作错误判断及处理。 (3)参数说明:参数 path字符串包含欲打开的文件路径及文件名,参数 mode 字符串则代表着流形态。 (4)举例

库打桩机制

匿名 (未验证) 提交于 2019-12-02 21:59:42
1.编译时打桩 linux>gcc -DCOMPILETIME -c mymalloc.c linux>gcc -I. -o intc int.c mymalloc.o linux>./intc 使用-I.参数,它会使C预处理器会在搜索通常的系统目录之前,现在当前目录中查找 mymalloc.c: #ifdef COMPILETIME #include <stdio.h> #include <malloc.h> void * mymalloc(size_t size){ void * ptr=malloc(size); printf("malloc(%d)=%p\n",(int)size,ptr); return ptr; } void myfree(void * ptr){ free(ptr); printf("free(%p)\n",ptr); } #endif malloc.h: #define malloc(size) mymalloc(size) #define free(ptr) myfree(ptr) void * mymalloc(size_t size); void myfree(void * ptr); int.c: #include <stdio.h> #include <malloc.h> int main(){ int * p=malloc(32);

系统调用IO和标准IO

匿名 (未验证) 提交于 2019-12-02 21:56:30
Ŀ¼ open close read write lseek ioctl 在Linux中一切皆文件,文件操作在Linux中是十分重要的。为此, Linux内核提供了一组用户进程与内核进行交互的接口用于对文件和设备进行访问控制,这些接口被称为系统调用。 系统调用对于应用程序最大的作用在于: 以统一的形式,为应用程序提供了一组文件访问的抽象接口,应用程序不需要关心文件的具体类型,也不用关心其内部实现细节。 常用的系统调用IO函数有5个:open、close、read、write、ioctl,此外还有个非系统调用IO函数lseek,系统调用IO都是不带缓冲的IO。 open open用于创建一个新文件或打开一个已有文件,返回一个非负的文件描述符fd。 0、1、2为系统预定义的文件描述符,分别代表STDIN_FILENO、STDOUT_FILENO、STDERR_FILENO。 #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> //成功返回文件描述符,失败返回-1 int open ( const char * pathname , int flags , ... /* mode_t mode */ ); flags参数一般在O_RDONLY、O_WRONLY和O_RDWR中选择指定一个

字符串函数构析

允我心安 提交于 2019-12-01 12:07:44
字符串函数构析 今日参加了一场笔试,刚好程序题问到一道strcpy函数构建,刚好之前看过字符串函数,同时网上文章大部分都是介绍了下函数的用法,缺少了函数的实现,今日就来自己构析下常见的字符串函数,字符串函数位于标准库的头文件string.h中,在使用函数时需引用该文件 strlen 函数原型 :size_t strlen(const char *s) 函数功能 :返回s的字符串函数(不包含结尾的0) 函数构析: size_t strlen(const char *s) /*size_t在不同架构下分别代表 unsigned int和 unsigned long*/ { int idx = 0; while(s[idx]!='\0') { idx++; } return idx; } strcmp 函数原型 :int mycmp(const char *s1,const char *s2) 函数功能 :比较两字符串,返回值为三种结果(以ascii码表对比) 0:s1==s2 正数:s1>s2 负数:s1<s2 函数构析: int mycmp(char *s1,const char *s2) { while(*s1 == *s2 && *s1 != '\0') { s1++; s2++; } return *s1 - *s2; } strcpy 函数原型 :char *strcpy