The bycopy() function

The bycopy() function copies a given number of bytes from one location to another.

Syntax

void bycopy(from, to, length)
   char *from;
   char *to;
   mint length;
from
A pointer to the first byte of the group of bytes that you want bycopy() to copy.
to
A pointer to the first byte of the destination group of bytes. The memory area to which to points can overlap the area to which the from argument points. In this case, Informix® ESQL/C does not preserve the value to which from points.
length
The number of bytes that you want bycopy() to copy.
Important: Take care not to overwrite areas of memory next to the destination area.

Example

This sample program is in the bycopy.ec file in the demo directory.
/*
   * bycopy.ec *

   The following program shows the results of bycopy() for three copy
   operations.
*/

#include <stdio.h>

char dest[20];

main()
{
    mint number1 = 12345;
    mint number2 = 0;
    static char string1[] = "abcdef";
    static char string2[] = "abcdefghijklmn";

    printf("BYCOPY Sample ESQL Program running.\n\n");

    printf("String 1=%s\tString 2=%s\n", string1, string2);
    printf("  Copying String 1 to destination string:\n");
    bycopy(string1, dest, strlen(string1));
    printf("  Result = %s\n\n", dest);

    printf("  Copying String 2 to destination string:\n");
    bycopy(string2, dest, strlen(string2));
    printf("  Result = %s\n\n", dest);

    printf("Number 1=%d\tNumber 2=%d\n", number1, number2);
    printf("  Copying Number 1 to Number 2:\n");
    bycopy( (char *) &number1, (char *) &number2, sizeof(int));
    printf("  Result = number1(hex) %08x, number2(hex) %08x\n",
            number1, number2);

    printf("\nBYCOPY Sample Program over.\n\n");
}

Output

BYCOPY Sample ESQL Program running.

String 1=abcdef  String2=abcdefghijklmn
  Copying String 1 to destination string:
  Result  = abcdef

  Copying String 2 to destination string:
  Result = abcdefghijklmn

Number 1=12345  Number2=0
  Copying Number 1 to Number 2:
  Result = number1(hex) 00003039, number2(hex) 00003039

BYCOPY Sample Program over.