ILE C/C++ Programmer's Guide

Converting String Literals in a Source File

You can convert the string literals in a source program from the point that the #pragma convert directive is specified to the end of the program. The #pragma convert directive specifies the CCSID to use for converting the string literals from that point onward in the program. The conversion continues until the end of the source or until another #pragma convert directive is specified.

If a CCSID with the value 65535 is specified, the CCSID of the root source member is assumed. If the source file CCSID value is 65535, CCSID 037 is assumed. The CCSID of the string literals before conversion is the same CCSID as the root source member. The CCSID can be either EBCDIC or ASCII.


The following example shows you how to convert the string literals in T1520CCS to ASCII CCSID 850 even though the CCSID of the source physical file is EBCDIC.

In this example, the TGTCCSID parameter is defaulted to *SOURCE.
  1. Type:


    To create the program T1520CCS using the following source:

    Figure 335. T1520CCS -- ILE C Source to Convert Strings and Literals

    /* This program uses the #pragma convert directive to convert */
    /* string literals. */
    #include <stdio.h>
    char EBCDIC_str[20] = "Hello World";
    #pragma convert(850) /* Use the #pragma convert */
    /* directive to convert the */
    /* string to ASCII, CCSID 850. */
    char ASCII_str[20] = "Hello World";
    #pragma convert(0) /* Stop string conversion. */
    int main(void)
    int i;
    printf ("EBCDIC_str(hex) = "); /* Print hex value of EBCDIC */
    for (i = 0; i < 11; ++i) /* string. */
    printf ("%X ",EBCDIC_str[i]);
    printf ("\n\n");
    printf ("ASCII_str(hex) = "); /* Print hex value of ASCII */
    for (i = 0; i < 11; ++i) /* string. */
    printf ("%X ",ASCII_str[i]);

    The CRTBNDC command creates the program T1520CCS in library MYLIB. Program T1520CCS converts the EBCDIC string Hello World to ASCII CCSID 850.

  2. To run the program T1520CCS, type:


    The output is as follows:

    |EBCDIC_str(hex) = C8 85 93 93 96 40 E6 96 99 93 84                              |
    |ASCII_str(hex) = 48 65 6C 6C 6F 20 57 6F 72 6C 64                               |
    |Press ENTER to end terminal session.                                            |

[ Top of Page | Previous Page | Next Page | Table of Contents ]