투케이2K

51. (C++) memcpy 함수 사용해 src 의 count 바이트를 dest 로 복사 실시 본문

C++

51. (C++) memcpy 함수 사용해 src 의 count 바이트를 dest 로 복사 실시

투케이2K 2023. 3. 12. 11:49
반응형

[개발 환경 설정]

개발 언어 : C++

 

[소스 코드]

 

// -----------------------------------------------------------------------------------------
//
// Created by KGH on 2023-02-12.
//
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [헤더 파일 import]

#include "Test.h"
#include <android/log.h>
// -----------------------------------------------------------------------------------------





// -----------------------------------------------------------------------------------------
// TODO [include 및 define 문 정의]
#include <iostream>
#include <string>

#define MAX_LEN 80

using namespace std;
// -----------------------------------------------------------------------------------------




// -----------------------------------------------------------------------------------------
// TODO [구현부 소스 코드 작성]
int main(void)
{

    /**
     * ------------------------------------
     * [요약 설명]
     * ------------------------------------
     * 1. memcpy() 함수는 src의 count 바이트를 dest로 복사합니다
     * ------------------------------------
     * 2. memcpy() 함수는 dest에 대한 포인터를 리턴합니다
     * ------------------------------------
     * */


    // [변수 선언 실시]
    char source[ MAX_LEN ] = "hello my name is twok";
    char target[ MAX_LEN ] = "hi my name is 2k";


    // [target 은 source 값을 복사]
    memcpy( target, source, sizeof(source));


    // [로그 출력 실시]
    //*
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");
    __android_log_print(ANDROID_LOG_INFO, "[C++] [LOG]", "After memcpy, target becomes \"%s\"\n", target);
    __android_log_print(ANDROID_LOG_WARN, "[C++] [LOG]", "%s", "=====================================================");
    // */


    return 0;
}
// --------------------------------------------------------------------------------------
 

[결과 출력]

 

W/[C++] [LOG]: =====================================================
I/[C++] [LOG]: After memcpy, target becomes "hello my name is twok"
W/[C++] [LOG]: =====================================================

 

반응형
Comments