Source Code Sample

The ILE C compiler recognizes source code written in any single-byte EBCDIC CCSID (Coded Character Set Identifier) except CCSID 290, 905 and 1026. See Internationalizing a Program for information on CCSIDs.

Some characters from the C and C++ character set are not available in all environments. You can enter these characters into a C or C++ source program using a sequence of three characters called a trigraph.

Note: For more information about using trigraph sequences, see the ILE C/C++ Language Reference.

C language onlyThe C compiler also supports digraphs. (The C++ compiler does not support digraphs.)

Figure 1. ILE C Source to Add Integers and Print Characters
/* This program reads input from the terminal, displays characters, */  
/* and sums and prints the digits. Enter a "+" character to         */  
/* indicate EOF (end-of-file).                                      */  
                                                                        
 #define MAXLEN 60               /* The maximum input line size.    */  
                                                                        
 #include <stdio.h>                                                     
 #include <ctype.h>                                                     
                                                                        
 void main(void)                                                        
 {                                                                      
    int  c;                                                             
    int  i = 0, j = 0;                                                  
    int  sum = 0;                                                       
    int  count, cnt;                                                    
    int  num[MAXLEN];            /* An array of digits.             */  
    char letter??(MAXLEN??);     /* An array of characters. Trigraphs   
                                   replace the square brackets.    */   
                                                                        
    while ( ( c = getchar( ) ) != '+' )                                 
    {                                                                   
       if ( isalpha ( c ) )      /* A test for an alphabetic        */  
       {                         /* character.                      */  
           letter[i++] = c;                                             
       }                                                                
       else if ( isdigit ( c ) ) /* A test for a decimal digit.     */  
       {                                                                
           num??(j++??) = c - '0';  /* Trigraphs replace the square     
                                       brackets.                   */   
       }                                                                
    } 
    printf ( "Characters are " );   
    for ( count = 0; count < i; ++count )   
    {                                           
       printf ( "%c", letter[count] );
     }
    printf( "\nSum of Digits is " );          
    for ( cnt = 0; cnt < j; ++cnt )           
    {                                         
        sum += num[cnt];                  
    }                                         
    printf ( "%d\n", sum );                   
 }