题目:自己定义一个函数,实现my_memcpy和my_memmove函数。题目分析:memcpy函数主要实现的是内存的拷贝,函数接受任意类型的参数,并且有拷贝个数的限制,函数与strcpy函数在功能上有相似点,也有不同点。memmove函数在memcpy函数的基础上解决了内存重叠的问题。下面是memcpy..
分类:
其他好文 时间:
2015-11-20 23:16:41
阅读次数:
320
1.模拟实现strcpy
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
char*my_strcpy(char*dst,constchar*src)
{
assert(dst!=NULL);
assert(src!=NULL);
char*ret=dst;
while((*dst++=*src++)!=‘\0‘)
;
returnret;..
分类:
编程语言 时间:
2015-11-19 16:57:52
阅读次数:
260
这里memcpy与memmove函数的模拟实现,需要用到空指针来传递参数,之后强制类型转换为char型,用size_t这个宏接受偏移量进行偏移,模拟实现如下:memcpy函数:void*my_memcpy(void*dst,constvoid*src,size_tcount)
{
assert(dst);
assert(src);
void*ret=dst;
while(count--)
{
..
分类:
编程语言 时间:
2015-11-19 07:16:11
阅读次数:
160
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
void*my_memcpy(void*p1,constvoid*p2,size_tcount)
{
assert(p1);
assert(p2);
char*dest=(char*)p1;
char*src=(char*)p2;
while(count--)
{
*dest++=*src++;
}
returnp1;
}
intmain()
{
floatar..
分类:
数据库 时间:
2015-11-19 07:15:07
阅读次数:
118
#define_CRT_SECURE_NO_WARNINGS1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
void*my_memcpy(void*p1,constvoid*p2,size_tcount)
{
assert(p1);
assert(p2);
char*dest=(char*)p1;
char*src=(char*)p2;
char*ret=dest;
while(count--)
{
*d..
分类:
编程语言 时间:
2015-11-19 07:14:53
阅读次数:
135
//思路:1.gethostbyname(szname);取得主机信息结构体// 2.memcpy(&ip_addr,phot->h_addr_list[0],4);从主机信息结构体中取出需要的32位ip地址ip_addr(二进制的)// 3.inet_ntop(AF_INET, &ip_a...
分类:
移动开发 时间:
2015-11-11 16:15:18
阅读次数:
1722
需要注意的是:第44、45行中,strlen是函数,sizeof是算符。strlen()是从内存的某个位置开始扫描,知道碰到第一个字符串结束符‘\0‘为止,然后返回计数器数值(不包括‘\0‘)。sizeof是一个操作符,简单地说,就是返回一个对象或者类型所占的内存字节数。strcpy和memcpy的区别:1..
分类:
其他好文 时间:
2015-11-10 01:47:05
阅读次数:
169
本文转自:http://my.oschina.net/renhc/blog/36345面试中如问到memcpy的实现,那就要小心了,这里有陷阱。先看下标准memcpy()的解释:?12void *memcpy(void *dst, const void *src, size_t n);//If co...
分类:
编程语言 时间:
2015-10-18 18:29:34
阅读次数:
163
因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类1. 利用memcpy拷贝内存数据 //自定义person结构体Cpp代码typedefstruct{intage;charname[20];}...
分类:
其他好文 时间:
2015-09-30 16:01:13
阅读次数:
258
最近用到了protobuf传输数据,但在protobuf之前还有个协议头。因为是重构,所以需要模拟协议头部。有如下代码string data;char buffer[256];memcpy(buffer, &header, sizeof(header));data.append(buffer);cl...
分类:
其他好文 时间:
2015-09-23 21:01:53
阅读次数:
210