Objectives :

  • File Name : string_copy_memcpy1.cpp
    • The string::copy function, copies characters from a string into an array
    • The function memcpy of string.h library, copies the content of source-buffer to target-buffer. NULL values are copied too.
    • The function like strcpy/strncpy, stops at  NULL bytes.
  • Code: string_copy_memcpy1.txt

Step: 1 Create a source file.

Step: 2 Edit and save Source file

Step: 3 Runtime Views:


Step: Brief Discussion: with Debug F8/Quincy

a) str.copy function : copies str->buffer, from 0 to 11 character, in an order of left to right.

Note if you reduce the length from 11 to 10, in this function" length=str.copy(buffer1,11,0);

b) cstring<string.h> memcpy function: Copies data from one (buffer1)  to another(buffer2)

c) new and delete operator

d) Copy and trim with

e) difference between memcpy and strncpy behind the scene. The strncpy/strcpy stops at NULL bytes, and memcpy will have NULL values