strcpy

extern char *strcpy(char *dest,char *source);
{
    assert((dest!=NULL)&&(source!=NULL));

    char *address=dest;
    while((*dest++=*source++)!='\0');

    return address;
}

  把source所指由NULL结束的字符串复制到dest所指的数组中。source和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳source的字符串。返回指向dest的指针。

memcpy

void *memcpy(void *dest, const void *source, size_t count)//没有对内存重叠进行检查
{
    assert((dest!=NULL)&&(source!=NULL));

    char* tmpDest=(char*)dest;
    char* tmpSource=(const char*)source;
    while(count--)
        *tmpDest++=*tmpSource++;
    return tmpDest;
}

memmove

  Copies the values of num bytes from the location pointed by source to the memory block pointed by destination. Copying takes place as if an intermediate buffer were used, allowing the destination and source to overlap

void* memmove(void* dest,const void* src,size_t num)
{
    assert((dest!=NULL)&&(src!=NULL));

    char* tmpDest=(char*)dest;
    char* tmpSrc=(const char*)src;

    if(src>dest||src+num<dest)
    {
        while(num--)
            *tmpDest++=*tmpSrc++;
    }
    else
    {
        tmpDest=dest+num-;
        tmpSrc=src+num-;
        while(num--)
            *tmpDest--=*tmpSrc--;
    }
    return dest;
}

strcpy&memcpy&memmove的更多相关文章

  1. strcpy,memcpy,memmove和内存重叠分析

    一:strcpy函数用法和实现: /* GNU-C中的实现(节选): */ char* strcpy(char *d, const char *s) { char *r=d; while((*d++= ...

  2. strcpy, mencpy, memmove三者区别

    首先来看strcpy,目的是实现字符串的复制,这里需要注意几个点: 1.判断指针的有效性 2.将复制后的指针地址返回,为了支持链式操作 3.不要忘记将字符串最后一个自负'\0'复制给dest 4.注意 ...

  3. 自己实现的库函数2(memset,memcmp,memcpy,memmove)

    memset,memcmp,memcpy,memmove是对内存进行管理的库函数,为了更好的理解和使用这几个函数,自己用C语言实现一下~ //内存设置函数void* my_memset(void* d ...

  4. memset memcmp memcpy memmove 自己实现

    memset memcmp memcpy memmove 自己实现 memset #include <stdio.h> #include <memory.h> #include ...

  5. memcpy/memmove?快速乘?

    memcpy?memmove? //#pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; ; ],b[n ...

  6. C的memset,memcpy,strcpy 的区别 及memset memcpy memmove源码

    extern void *memcpy(void *dest,void *src,unsigned int count);#include <string.h>   功能:由src所指内存 ...

  7. strcpy和memcpy,memmove函数的区别

    strcpy和memcpy的区别 strcpy和memcpy都是标准C库函数,它们有下面的特点. strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制 ...

  8. strcpy, memcpy, memset函数

    一. strcpy函数 原型声明:char *strcpy(char* dest, const char *src);   头文件:#include <string.h> 和 #inclu ...

  9. 访谈将源代码的函数 strcpy/memcpy/atoi/kmp/quicksort

    一.社论 继上一次发表了一片关于參加秋招的学弟学妹们怎样准备找工作的博客之后,反响非常大.顾在此整理一下,以便大家复习.好多源自july的这篇博客,也有非常多是我自己整理的.希望大家可以一遍一遍的写. ...

随机推荐

  1. 201871010116-祁英红《面向对象程序设计(java)》第十周学习总结

    博文正文开头格式:(2分) 项目 内容 <面向对象程序设计(java)> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://ww ...

  2. number.toFixed和Math.round与保留小数

    如果你baidu/google过或者自己写过保留两位小数,那下面这代码一定不陌生 Math.round(number*100)/100 那你使用过Number.prototype.toFixed这个方 ...

  3. commons-httpclient 和 httpclient 区别

    今天在看项目的pom的时候,发现里面有这么两个包依赖. <dependency> <groupId>commons-httpclient</groupId> < ...

  4. 【oracle】查看表空间对应文件所在位置

    select file_name , tablespace_name from dba_data_files;select * from dba_data_files;

  5. 【2019.8.15 慈溪模拟赛 T1】插头(plugin)(二分+贪心)

    二分 首先,可以发现,最后的答案显然满足可二分性,因此我们可以二分答案. 然后,我们只要贪心,就可以验证了. 贪心 不难发现,肯定会优先选择能提供更多插座的排插,且在确定充电器个数的情况下,肯定选择能 ...

  6. Codeforces Round #598 (Div. 3) C. Platforms Jumping 贪心或dp

    C. Platforms Jumping There is a river of width n. The left bank of the river is cell 0 and the right ...

  7. golang数据结构之选择排序

    //SelectSort 选择排序 func SelectSort(arr *[]int) { ; i < len(arr); i++ { tmp := arr[i] index := i ; ...

  8. 【文本处理命令】之awk命令详解

    一.awk命令简介 awk 是一种很棒的语言,它适合文本处理和报表生成,其语法较为常见,借鉴了某些语言的一些精华,如 C 语言等.在 linux 系统日常处理工作中,发挥很重要的作用,掌握了 awk将 ...

  9. C语言--计算程序执行时间

    C语言–计算程序执行时间1. gettimeofday精度1us #include<stdio.h>#include<sys/time.h> int main(){ /* 定义 ...

  10. WPF之动态加载曲线

    首先说一下思路: 先创建一个控件(其实就是一个canvas),在canvas里面生成一条线,给这条线绑定一个PointCollection,在主界面中用一个定时器改变这个PointCollection ...