The deccopy() function

The deccopy() function copies one decimal structure to another.

Syntax

void deccopy(source, target)
   dec_t *source;
   dec_t *target;
source
A pointer to the value held in the source decimal structure.
target
A pointer to the target decimal structure.

The deccopy() function does not return a status value. To determine the success of the copy operation, look at the contents of the decimal structure to which the target argument points.

Example

The file deccopy.ec in the demo directory contains the following sample program.
/*
   * deccopy.ec *

   The following program copies one DECIMAL number to another.
*/

#include <stdio.h>

EXEC SQL include decimal;

char string1[] = "12345.6789";
char result[41];

main()
{
    int x;
    dec_t num1, num2;

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

    printf("String = %s\n", string1);
    if (x = deccvasc(string1, strlen(string1), &num1))
      {
      printf("Error %d in converting string1 to DECIMAL\n", x);
      exit(1);
      }
    printf("Executing: deccopy(&num1, &num2)\n");
    deccopy(&num1, &num2);
    if (x = dectoasc(&num2, result, sizeof(result), -1))
      {
      printf("Error %d in converting num2 to string\n", x);
      exit(1);
      }
    result[40] = '\0';
    printf("Destination = %s\n", result);

    printf("\nDECCOPY Sample Program over.\n\n");
    exit(0);
}

Output

DECCOPY Sample ESQL Program running.

String = 12345.6789
Executing: deccopy(&num1, &num2)
Destination = 12345.6789 

DECCOPY Sample Program over.