memcpy

Posted on 2012-03-14 22:04  无忧consume  阅读(194)  评论(0编辑  收藏  举报

#include <string.h>
#include <stdio.h>

int main()
{
    char a[30] = "string (a)";
    char b[30] = "hi\0zengxiaolong";
    int i;

    strcpy(a, b);             //a[30] = "hi\0ing (a)"
    printf("strcpy():");
    for(i = 0; i < 30; i++)
        printf("%c", a[i]);   //hi ing (a)


    memcpy(a, b, 30);         //a[30] = "hi\0zengxiaolong"
    printf("\nmemcpy():");
    for(i = 0; i < 30; i++)
        printf("%c", a[i]);   //hi zengxiaolong
    printf("\n i = %d\n", i); //30

}

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes